1 00:00:00,790 --> 00:00:03,190 The following content is provided under a Creative 2 00:00:03,190 --> 00:00:04,730 Commons license. 3 00:00:04,730 --> 00:00:07,030 Your support will help MIT OpenCourseWare 4 00:00:07,030 --> 00:00:11,390 continue to offer high-quality educational resources for free. 5 00:00:11,390 --> 00:00:13,990 To make a donation or view additional materials 6 00:00:13,990 --> 00:00:17,860 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,860 --> 00:00:18,820 at ocw.mit.edu. 8 00:00:23,090 --> 00:00:26,580 ANA BELL: So let's look at the example, 9 00:00:26,580 --> 00:00:30,610 or the in-class exercise, with while loops. 10 00:00:30,610 --> 00:00:35,620 Oh good, we got some varying responses here, perfect. 11 00:00:35,620 --> 00:00:39,940 So the code is, "You're in the Lost Forest. 12 00:00:39,940 --> 00:00:40,990 Go left or right?" 13 00:00:40,990 --> 00:00:41,680 OK. 14 00:00:41,680 --> 00:00:43,420 So here, the while loop is checking 15 00:00:43,420 --> 00:00:47,380 if the input is equal to this particular string. 16 00:00:47,380 --> 00:00:48,010 OK. 17 00:00:48,010 --> 00:00:49,660 And if it is, type the same thing again 18 00:00:49,660 --> 00:00:51,700 and ask them for more input. 19 00:00:51,700 --> 00:00:57,720 So my question was, what happens when you type in "R-i-g-h-t?" 20 00:00:57,720 --> 00:01:00,850 And I think the majority of the class is getting it right. 21 00:01:00,850 --> 00:01:03,100 And maybe the people who answered 22 00:01:03,100 --> 00:01:05,470 this are maybe changing their answer to something else, 23 00:01:05,470 --> 00:01:06,250 but you're right. 24 00:01:06,250 --> 00:01:09,976 So you ask the question again, "Go left or right?" 25 00:01:09,976 --> 00:01:11,350 And that's because Python, again, 26 00:01:11,350 --> 00:01:13,460 is very, very particular. 27 00:01:13,460 --> 00:01:16,150 We're telling it that the user input 28 00:01:16,150 --> 00:01:18,400 must match this string exactly. 29 00:01:18,400 --> 00:01:25,280 So "R-i-g-h-t" is going to-- even though it says right, 30 00:01:25,280 --> 00:01:27,380 it doesn't match up. 31 00:01:27,380 --> 00:01:30,440 So if you wanted-- I'll just show you in this example here-- 32 00:01:30,440 --> 00:01:34,250 if you wanted to take care of that case, 33 00:01:34,250 --> 00:01:39,280 then you'd add this little-- you'd expand on this line right 34 00:01:39,280 --> 00:01:46,510 here, which says, "while n = = 'right' or n = = to "R-i-g-h-t" 35 00:01:46,510 --> 00:01:49,290 or whatever other cases you'd want to take care of. 36 00:01:49,290 --> 00:01:50,840 OK.