1 00:00:00,770 --> 00:00:03,220 - In this self check exercise we'd like you to use 2 00:00:03,220 --> 00:00:05,760 the string method format that we just introduced 3 00:00:05,760 --> 00:00:08,240 in the preceding video to re-implement 4 00:00:08,240 --> 00:00:11,300 the last three self check exercises. 5 00:00:11,300 --> 00:00:13,870 So to make that easier for you I've gone ahead 6 00:00:13,870 --> 00:00:16,660 and copied in those descriptions 7 00:00:16,660 --> 00:00:18,660 from the previous three self checks. 8 00:00:18,660 --> 00:00:22,270 So go ahead and take a look at the descriptions again here. 9 00:00:22,270 --> 00:00:25,440 But this time rather than using F strings, 10 00:00:25,440 --> 00:00:30,440 use the format method being called on a format string. 11 00:00:31,010 --> 00:00:33,190 Go ahead and pause the video to try that then 12 00:00:33,190 --> 00:00:34,803 come back and see the answers. 13 00:00:39,680 --> 00:00:43,570 Okay, let's go ahead and reveal the answer for part A here. 14 00:00:43,570 --> 00:00:46,640 So again we were using the type specifier C 15 00:00:46,640 --> 00:00:51,060 to display the character codes 58, 45 and 41. 16 00:00:51,060 --> 00:00:53,120 So I'll go ahead and expand that here. 17 00:00:53,120 --> 00:00:56,310 Now as you can see we have three placeholders 18 00:00:56,310 --> 00:00:58,620 all of which have a colon and a C. 19 00:00:58,620 --> 00:01:02,610 The colon introduces the type specifiers and the type 20 00:01:02,610 --> 00:01:06,100 specifier C says to take a numeric value and display 21 00:01:06,100 --> 00:01:08,620 its character representation. 22 00:01:08,620 --> 00:01:13,330 So 58, 45, and 41, when we display those again are going 23 00:01:13,330 --> 00:01:16,740 to give us the colon, the dash, and the smiley face. 24 00:01:16,740 --> 00:01:20,220 In this case, we had spaces in between them which is why 25 00:01:20,220 --> 00:01:22,380 the spaces are being displayed there. 26 00:01:22,380 --> 00:01:25,890 So if I go ahead and get rid of those spaces and re-execute 27 00:01:25,890 --> 00:01:29,880 you can see that we get the smiley face in that case. 28 00:01:29,880 --> 00:01:34,880 Now separately for part B, we wanted to display Amanda 29 00:01:35,470 --> 00:01:37,440 right, center, and left aligned. 30 00:01:37,440 --> 00:01:41,360 So, in this case, we have square brackets around 31 00:01:41,360 --> 00:01:44,260 a placeholder because we wanted to be able to see 32 00:01:44,260 --> 00:01:46,990 the formatted values with their spacing. 33 00:01:46,990 --> 00:01:50,170 And so we have so a placeholder here that says whatever 34 00:01:50,170 --> 00:01:54,070 is at index position zero should be formatted 35 00:01:54,070 --> 00:01:56,520 right aligned in a field of 10. 36 00:01:56,520 --> 00:02:00,630 Whatever is at position zero, again Amanda, should be center 37 00:02:00,630 --> 00:02:03,820 aligned in a field of 10 and whatever is at position zero 38 00:02:03,820 --> 00:02:06,170 should be left aligned in a field of 10. 39 00:02:06,170 --> 00:02:10,200 Notice that every one of these format specifiers is using 40 00:02:10,200 --> 00:02:13,630 the index zero so we're repeatedly going to insert 41 00:02:13,630 --> 00:02:16,570 that value throughout the format string. 42 00:02:16,570 --> 00:02:19,200 And then print the string and as you can see, 43 00:02:19,200 --> 00:02:23,320 we get the same results as two self check exercises ago. 44 00:02:23,320 --> 00:02:27,010 And then finally for part C here, we wanted to format 45 00:02:27,010 --> 00:02:29,010 these two floating point values. 46 00:02:29,010 --> 00:02:32,550 Again, in 10 digit fields preceded by their signs 47 00:02:32,550 --> 00:02:35,610 with thousands separators and two digits 48 00:02:35,610 --> 00:02:37,270 to the right of the decimal point. 49 00:02:37,270 --> 00:02:39,810 So if we go ahead and expand that out here. 50 00:02:39,810 --> 00:02:41,940 Let's take a look at our format specifiers 51 00:02:41,940 --> 00:02:43,700 both of them are identical. 52 00:02:43,700 --> 00:02:48,700 We're going to be using a sign in front of a ten character 53 00:02:48,900 --> 00:02:53,780 field using thousand separators and two digits to the right 54 00:02:53,780 --> 00:02:55,920 of the decimal point for the floating point number. 55 00:02:55,920 --> 00:02:57,530 And we did that twice here. 56 00:02:57,530 --> 00:03:00,230 And as you can see, we do indeed 57 00:03:00,230 --> 00:03:02,563 get that same formatted result.