1 00:00:00,380 --> 00:00:02,819 All right, now let's look at while.py. 2 00:00:02,819 --> 00:00:05,020 There are only three problems in this one but 3 00:00:05,020 --> 00:00:07,970 they might prove more difficult than the ones in for.py. 4 00:00:07,970 --> 00:00:08,610 While loops, 5 00:00:08,610 --> 00:00:13,070 if you don't remember, will execute until their condition evaluates as false. 6 00:00:13,070 --> 00:00:15,180 Because of this, they're known as indefinite loops, 7 00:00:15,180 --> 00:00:17,960 because they can run an indefinite number of times. 8 00:00:17,960 --> 00:00:21,070 For loops on the other hand, will only run a certain number of times. 9 00:00:21,070 --> 00:00:24,670 I don't think it's even possible to make infinite for loops in Python. 10 00:00:24,670 --> 00:00:28,380 You can use the continue keyword to skip an iteration of the loop. 11 00:00:28,380 --> 00:00:31,710 Or you can use the break keyword to completely stop the loop. 12 00:00:31,710 --> 00:00:36,040 Both of those keywords work on for loops too, but they're used there less often. 13 00:00:36,040 --> 00:00:37,750 Let's take a look at the problems. 14 00:00:37,750 --> 00:00:41,670 The first problem, warm the oven, needs you to add 25 degrees to 15 00:00:41,670 --> 00:00:44,940 the current oven temperature until it's at 350 degrees. 16 00:00:44,940 --> 00:00:47,600 On each iteration, print out the current temperature. 17 00:00:47,600 --> 00:00:50,440 When the loop is done, print out The oven is ready! 18 00:00:50,440 --> 00:00:53,900 You can use the while loop's else class here if you want. 19 00:00:53,900 --> 00:00:58,540 For the second problem, you'll need to finish the function that I started. 20 00:00:58,540 --> 00:01:00,530 Yeah, I'm gonna call that started. 21 00:01:00,530 --> 00:01:03,310 Anyway, create an infinite while loop. 22 00:01:03,310 --> 00:01:06,470 Since while loops run until their condition is false, 23 00:01:06,470 --> 00:01:10,310 what value could you use to make the condition never false? 24 00:01:10,310 --> 00:01:12,820 While the loop is running, ask the user for a number and 25 00:01:12,820 --> 00:01:14,720 add that number to the numbers list. 26 00:01:14,720 --> 00:01:19,270 If they give you a q, a string q, instead though, end the loop. 27 00:01:19,270 --> 00:01:22,990 When the loop ends, print out all of the numbers, the sum of the numbers, and 28 00:01:22,990 --> 00:01:24,930 the average of all of the numbers. 29 00:01:24,930 --> 00:01:28,280 This solution doesn't absolutely require you to use break, but 30 00:01:28,280 --> 00:01:31,170 you'll probably find it easier to solve that way. 31 00:01:31,170 --> 00:01:33,430 Finally, the third problem. 32 00:01:33,430 --> 00:01:37,310 You might have come across the common programming problem known as fizzbuzz, 33 00:01:37,310 --> 00:01:40,969 where you have to loop through all of the numbers from say, one to 100. 34 00:01:40,969 --> 00:01:45,384 And if the number is divisible by 3 or 5 or 7 or some combination of them or 35 00:01:45,384 --> 00:01:49,420 some other number, then you print out fizz, buzz, or fizzbuzz. 36 00:01:49,420 --> 00:01:52,700 Now I don't want you to do exactly that, but it's something similar. 37 00:01:52,700 --> 00:01:56,088 Write a while loop that checks the value of the current variable. 38 00:01:56,088 --> 00:01:58,180 This one right here called current. 39 00:01:58,180 --> 00:02:01,290 If it's 101, you should end the loop. 40 00:02:01,290 --> 00:02:04,350 On each iteration, increment the number by 1. 41 00:02:04,350 --> 00:02:07,376 If the new number is divisible by 3, 5, 42 00:02:07,376 --> 00:02:11,360 or both, print it out, otherwise, skip the number. 43 00:02:11,360 --> 00:02:13,000 All right, see how you do on these challenges. 44 00:02:13,000 --> 00:02:14,790 And I'll be back with the solutions in a minute.