1 00:00:00,210 --> 00:00:03,810 Before we start, did you try solving the workbook yourself? 2 00:00:03,840 --> 00:00:09,600 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,820 --> 00:00:12,600 Welcome to Work Book 5.7. 4 00:00:12,620 --> 00:00:15,890 It tells us to see learn the part for detailed instructions. 5 00:00:15,890 --> 00:00:20,930 Let's do just that task One is to make a4a loop that counts from 0 to 18. 6 00:00:21,050 --> 00:00:22,850 So we will say four. 7 00:00:24,110 --> 00:00:29,990 The counter is going to start an AI equaling zero and the four loop is going to keep running so long 8 00:00:29,990 --> 00:00:32,540 as AI is smaller than 19. 9 00:00:34,800 --> 00:00:40,440 Once we reach 19, we want the loop to break and then we'll say I plus, plus. 10 00:00:41,890 --> 00:00:45,250 And every time the loop runs, we're going to print. 11 00:00:47,290 --> 00:00:48,850 I guess, the number itself. 12 00:00:49,660 --> 00:00:49,960 All right. 13 00:00:49,960 --> 00:00:52,330 It's not worth visualizing the runtime just yet. 14 00:00:52,360 --> 00:00:59,120 Task two is to set up an if ls if L statement, which checks if a number is a multiple of three. 15 00:00:59,140 --> 00:01:00,790 Market forces five. 16 00:01:00,790 --> 00:01:01,990 Market Buzz. 17 00:01:02,020 --> 00:01:05,680 If it's a multiple of three and five market forces Buzz. 18 00:01:05,800 --> 00:01:13,990 Easy enough now for a number to be a multiple of three, let's say like nine, 12 or 15. 19 00:01:14,380 --> 00:01:19,390 All of these numbers divided by three return a remainder of zero. 20 00:01:19,780 --> 00:01:21,700 Here we can say if. 21 00:01:22,930 --> 00:01:25,660 The number that's currently being iterated through. 22 00:01:25,660 --> 00:01:30,400 If that number modulus three, returns a remainder of zero. 23 00:01:32,800 --> 00:01:36,880 Then we mark this number as fiz. 24 00:01:41,750 --> 00:01:49,190 But if the current number being iterated through, if dividing it by five returns a remainder of zero. 25 00:01:50,160 --> 00:01:52,860 Then we mark it as buzz. 26 00:01:54,100 --> 00:01:56,260 Not sure why Autocomplete is not working. 27 00:01:59,100 --> 00:02:00,240 Otherwise. 28 00:02:01,160 --> 00:02:08,210 If that number modulus three equals zero and modulus five equals zero. 29 00:02:08,570 --> 00:02:14,540 So if the number being iterated through is a multiple of three and is a multiple of five, then we market 30 00:02:14,540 --> 00:02:16,160 as fest buzz. 31 00:02:24,020 --> 00:02:24,350 All right. 32 00:02:24,350 --> 00:02:24,990 I think we're good. 33 00:02:25,010 --> 00:02:29,630 I'm going to put a breakpoint right here, and let's see if what we have currently works. 34 00:02:32,630 --> 00:02:34,850 So I is going to start at zero now. 35 00:02:34,850 --> 00:02:41,690 Zero divided by three is going to return a remainder of zero and zero divided by five is also going 36 00:02:41,690 --> 00:02:43,340 to return a remainder of zero. 37 00:02:43,340 --> 00:02:49,640 So while this meets the requirements for phase buzz, what's going to print instead is physx. 38 00:02:51,390 --> 00:02:58,480 Because the first condition gets satisfied and it marks our number zero as far as that is not good. 39 00:02:58,500 --> 00:03:00,210 You will remember, I'll learn the part. 40 00:03:00,210 --> 00:03:01,980 I left you with a hint. 41 00:03:02,220 --> 00:03:08,040 There are three conditions for fizz, buzz and fizz buzz, and you need to be careful about their order. 42 00:03:08,070 --> 00:03:13,230 If something is Physx buzz, it also satisfies the conditions for Physx and buzz. 43 00:03:13,230 --> 00:03:15,030 So the number is zero. 44 00:03:15,510 --> 00:03:22,680 It satisfied the conditions for Physx buzz, but it also satisfies the condition for Physx because this 45 00:03:22,680 --> 00:03:25,350 executed first it marked it as physx. 46 00:03:25,380 --> 00:03:33,120 So what we need to do is make sure that the requirements for Physx buzz take precedence over the others. 47 00:03:34,080 --> 00:03:40,080 So first we check if something meets the requirements for MBAs. 48 00:03:40,170 --> 00:03:44,640 If it doesn't, then we check if it's fizz or buzz. 49 00:03:45,500 --> 00:03:46,480 No Right. 50 00:03:46,490 --> 00:03:50,630 And that was basically the entire trick behind this workbook. 51 00:03:53,640 --> 00:03:59,640 So zero divided by three returns a remainder of zero divided by five returns a remainder of zero. 52 00:03:59,640 --> 00:04:01,650 So it is marked as sbas. 53 00:04:01,650 --> 00:04:03,090 That is perfect. 54 00:04:03,090 --> 00:04:04,650 Let me put some space. 55 00:04:06,370 --> 00:04:07,980 Are we doing that? 56 00:04:09,920 --> 00:04:17,180 All right, now I equals one after we increment it, one divided by three does not return a remainder 57 00:04:17,180 --> 00:04:21,800 of zero, nor does it return a remainder of zero if divided by five. 58 00:04:21,800 --> 00:04:23,660 So it's not fizz buzz. 59 00:04:23,660 --> 00:04:24,770 It's not fizz. 60 00:04:24,770 --> 00:04:26,120 It's not buzz either. 61 00:04:26,120 --> 00:04:27,650 So it gets skipped. 62 00:04:27,680 --> 00:04:29,690 Same thing goes for number two. 63 00:04:31,100 --> 00:04:36,740 Now the number three divided by three does return a remainder of zero, but it does not satisfy this 64 00:04:36,740 --> 00:04:37,580 requirement. 65 00:04:37,580 --> 00:04:42,380 So this whole thing returns false, but it does satisfy this requirement. 66 00:04:42,380 --> 00:04:44,450 So three gets marked as fiz. 67 00:04:44,450 --> 00:04:45,740 That is perfect. 68 00:04:47,820 --> 00:04:48,710 The number four. 69 00:04:48,720 --> 00:04:50,130 Again, nothing. 70 00:04:50,400 --> 00:04:54,360 The number five does meet this requirement, not this one. 71 00:04:54,360 --> 00:04:57,920 So this gets evaluated to false does not run. 72 00:04:57,930 --> 00:04:59,910 This will also be false. 73 00:05:00,420 --> 00:05:03,960 Five divided by five does return a remainder of zero. 74 00:05:03,960 --> 00:05:06,450 So this gets marked as buzz. 75 00:05:06,840 --> 00:05:14,190 And if I just press continue to resume execution, naturally there are no other breakpoints, so the 76 00:05:14,190 --> 00:05:15,750 whole thing completes. 77 00:05:15,840 --> 00:05:23,580 Let's see if what we have matches what's honoring the part 0356 phase Buzz phase, Buzz, fist phase. 78 00:05:25,750 --> 00:05:28,570 And that is exactly what we have in our terminal. 79 00:05:28,570 --> 00:05:29,700 That is perfect. 80 00:05:29,710 --> 00:05:32,740 I hope you enjoyed this breakpoint session.