All language subtitles for 045 Day 4 Project_ Rock Paper Scissors.en

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French Download
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,120 --> 00:00:05,580 All right, guys, so now that we've loaded up all the knowledge that we need into our brains, it's 2 00:00:05,580 --> 00:00:08,730 time to tackle the final project of the day. 3 00:00:09,140 --> 00:00:14,460 And as I showed you in the beginning of the day, it's a Rock Paper Scissors game that we can play 4 00:00:14,460 --> 00:00:15,380 with the computer. 5 00:00:16,050 --> 00:00:22,170 So the game starts out by asking you to type 0 for rock, 1 for paper, or 2 for scissors. 6 00:00:22,420 --> 00:00:29,820 So let's go ahead and type two for scissors, and then it's going to show you a graphic of your choice scissors, 7 00:00:30,210 --> 00:00:35,730 and then the choice the computer made, which is rock. And of course, rock beats scissors 8 00:00:35,730 --> 00:00:36,870 so you lose. 9 00:00:37,380 --> 00:00:44,610 What this game boils down to is some way of randomly making a choice between rock, paper, or scissors 10 00:00:45,030 --> 00:00:50,970 and then comparing that choice that the computer randomly generated against your choice. 11 00:00:51,330 --> 00:00:57,450 And then based on the rules of rock, paper, and scissors, determining whether if you won, you lost or 12 00:00:57,450 --> 00:00:59,790 whether if you had a draw. 13 00:01:01,080 --> 00:01:06,570 While I was looking around, I actually came across the world rock paper scissors association. 14 00:01:07,440 --> 00:01:12,630 And they have the official rules of the state of Rock Paper Scissors. 15 00:01:13,200 --> 00:01:17,080 If you're not familiar with this game, it might be worth checking out this website. 16 00:01:17,610 --> 00:01:20,100 Here are the three shapes of rock, paper, scissors. 17 00:01:20,490 --> 00:01:27,330 And then the rules are that rock wins against scissors, scissors wins against paper, and paper wins 18 00:01:27,330 --> 00:01:28,440 against rock. 19 00:01:29,100 --> 00:01:36,420 Having all of this in mind, head over to replit/@appbrewery/ rock-paper-scissors-start 20 00:01:36,780 --> 00:01:40,170 and go ahead and just fork the starting project. 21 00:01:40,860 --> 00:01:47,700 Now you'll notice that in the starting project, I've already got the ASCII art for rock, paper and scissors 22 00:01:47,700 --> 00:01:50,870 in here and they're each saved to a variable. 23 00:01:51,390 --> 00:01:58,170 So what that means is that you can start out by just having a go at printing out let's say a rock. 24 00:01:59,040 --> 00:02:01,110 And remember that these are variable names. 25 00:02:01,110 --> 00:02:04,410 They're not strings, so they don't need the double quotes around them. 26 00:02:04,860 --> 00:02:05,910 So let's run that. 27 00:02:05,910 --> 00:02:12,450 And you can see what we get printed is the particular ASCII art that I chose in my print statement. 28 00:02:13,380 --> 00:02:16,080 So this is already yours. 29 00:02:16,080 --> 00:02:22,890 But as you'll notice, there's no other logic that I've provided you and you are going to rely on what 30 00:02:22,890 --> 00:02:28,650 you learned in the previous days and most importantly, what you've learned in today's lessons to be 31 00:02:28,650 --> 00:02:30,090 able to complete this challenge. 32 00:02:30,420 --> 00:02:36,330 And it's worth comparing the outcome against the game of Rock Paper Scissors that I'll link to. 33 00:02:37,200 --> 00:02:42,030 There's a couple of things to think about, namely, how are you going to decide who won or who lost? 34 00:02:42,330 --> 00:02:49,170 How are you going to get the computer to choose a random shape, rock, paper, scissors, and how you 35 00:02:49,170 --> 00:02:54,420 actually get this game to work in the same way that is demoed in this final version? 36 00:02:55,320 --> 00:02:59,400 I'm going to go quiet now and I'm going to let you pause the video. 37 00:02:59,790 --> 00:03:04,980 And I want you to spend at least ten or fifteen minutes working on this. 38 00:03:05,250 --> 00:03:10,170 And if you get stuck, just try some things out or maybe watch some of the previous videos in the day 39 00:03:10,470 --> 00:03:12,840 and just try to give it your best 40 00:03:12,840 --> 00:03:15,120 go, and do a lot of struggling. 41 00:03:15,510 --> 00:03:16,950 Hopefully you're going to succeed. 42 00:03:16,950 --> 00:03:20,940 And once you're done, head back over here and I'll go through the solution with you. 43 00:03:21,180 --> 00:03:22,320 So pause the video now. 44 00:03:25,760 --> 00:03:30,860 All right, so we know that we've got all of this ASCII art, but for the moment, I'm just going to 45 00:03:30,860 --> 00:03:35,150 start off by putting down the basic logic of this game. 46 00:03:35,570 --> 00:03:41,840 And it's really helpful for you as well if you start thinking about breaking down the larger problem, 47 00:03:41,840 --> 00:03:47,930 which is making the Rock Paper Scissors game into smaller problems that you can solve, like generating 48 00:03:47,930 --> 00:03:50,110 a random number between one and three. 49 00:03:50,420 --> 00:03:55,820 So we have some sort of proxy for Rock Paper Scissors. And then maybe thinking about putting down 50 00:03:55,820 --> 00:04:02,360 the logic, well, if the computer chose scissors and I chose paper, then I'm going to lose. 51 00:04:02,690 --> 00:04:07,150 Or if the computer chose rock and I chose paper, then I'm going to win. 52 00:04:07,550 --> 00:04:14,270 And putting that down on a flowchart using draw.io or something like that can make this challenge a lot 53 00:04:14,270 --> 00:04:15,350 easier as well. 54 00:04:16,580 --> 00:04:22,100 But without further ado, the first thing I need to do is to produce a user choice. 55 00:04:22,610 --> 00:04:28,120 Now, this is going to be the one that the user chose when they typed in a value. 56 00:04:28,610 --> 00:04:32,900 And in order to get the value from them, I'm going to need to use a input. 57 00:04:33,440 --> 00:04:40,610 And inside the input, I'm going to put the following prompt asking the user, what do you choose? 58 00:04:40,610 --> 00:04:44,180 Type 0 for rock, 1 for paper or 2 for scissors. 59 00:04:44,750 --> 00:04:51,140 Now, once I get hold of this input, hopefully, if the user is following my instructions, they're going 60 00:04:51,140 --> 00:04:54,610 to type some sort of number, either zero or one or two. 61 00:04:55,190 --> 00:05:01,130 Now that I've gotten hold of what the user wants to choose, the next thing to do is figure out what 62 00:05:01,130 --> 00:05:02,690 the computer is going to choose. 63 00:05:03,080 --> 00:05:09,050 So I'm going to make another variable called computer_choice and I'm going to generate a random number. 64 00:05:09,410 --> 00:05:13,070 So to do that, remember, we have to import the random module. 65 00:05:15,020 --> 00:05:22,250 And then we can start using it to generate random whole numbers by using random.randint. 66 00:05:23,090 --> 00:05:30,170 And then the range is going to be between zero and two, because this is what I asked the user to do. 67 00:05:30,170 --> 00:05:33,190 Type 0 for rock, 1 for paper, 2 for scissors. 68 00:05:33,530 --> 00:05:37,850 So the computer is also going to choose between 0, 1 or 2. 69 00:05:39,110 --> 00:05:44,870 Now that I've got the computer_choice, I'm actually going to just print it out for now instead of printing 70 00:05:44,870 --> 00:05:48,860 out the actual shape, I'm just going to print out the number. 71 00:05:48,890 --> 00:05:54,680 So computer chose and then let's go ahead and add a fstring. 72 00:05:57,020 --> 00:06:00,300 And of course, that requires the F in front of the string. 73 00:06:01,130 --> 00:06:07,130 So now if we just play the game as it is, remember that testing up while you're developing it is really, 74 00:06:07,130 --> 00:06:08,150 really good practice. 75 00:06:08,360 --> 00:06:14,120 It picks up on the bugs that you make along the way instead of waiting until the end when you've done 76 00:06:14,120 --> 00:06:14,540 everything 77 00:06:14,540 --> 00:06:18,500 and then it doesn't work and you have to untangle all of the lines of code. 78 00:06:19,160 --> 00:06:24,200 At this point, I've already realized that it's actually not so great getting the user to type on this 79 00:06:24,200 --> 00:06:24,670 line. 80 00:06:25,460 --> 00:06:29,940 What I would much rather is to start a new line for them to type their answer on. 81 00:06:30,560 --> 00:06:34,040 So if I run the code again, then it should look a bit like this. 82 00:06:34,040 --> 00:06:37,970 My prompt is now here. So I'm going to choose 0 for Rock. 83 00:06:38,510 --> 00:06:41,840 And then it tells me that computer also chose zero. 84 00:06:42,290 --> 00:06:44,000 So in this case, this would be a draw. 85 00:06:44,450 --> 00:06:49,730 But if I played this game again, you can see that the computer is probably going to choose something 86 00:06:49,730 --> 00:06:50,260 different. 87 00:06:50,450 --> 00:06:51,860 So I chose rock again 88 00:06:51,860 --> 00:06:54,140 the computer chose 1, which is paper. 89 00:06:54,950 --> 00:07:02,960 So now we can start thinking about how do we compare these two choices and how can we define the logic 90 00:07:02,960 --> 00:07:04,610 of Rock Paper Scissors? 91 00:07:05,240 --> 00:07:12,230 So I know that paper beats rock, scissors beats paper and rock will beat scissors. 92 00:07:12,680 --> 00:07:21,280 So if zero is rock, one is paper and two is scissors, then two beats one and one beats zero. 93 00:07:21,590 --> 00:07:28,010 So that's very simple for us to check in terms of using if statements, 94 00:07:28,010 --> 00:07:28,280 right? 95 00:07:28,280 --> 00:07:29,930 We could simply just check 96 00:07:30,410 --> 00:07:40,550 well, if the computer choice is greater than the user choice, well then this probably means that the 97 00:07:40,760 --> 00:07:42,350 computer wins. 98 00:07:43,590 --> 00:07:51,810 But this is not true in all cases, right? Because if the computer chose 2 for scissors and the user 99 00:07:51,810 --> 00:07:57,240 chose 0 for rock, then the user should win rather than the computer winning. 100 00:07:57,450 --> 00:08:01,880 So we actually have some exceptions to this rule. 101 00:08:02,790 --> 00:08:08,520 How can we catch the exceptions before we go down to this level of generalization? 102 00:08:09,240 --> 00:08:16,830 Well, we could instead of using this as an if, we use this as an elif and we create another if statement 103 00:08:16,830 --> 00:08:27,210 which says, well, if the user_choice is equal to zero, so if the user chose rock and the computer_choice 104 00:08:27,660 --> 00:08:34,170 was 2, well then this means that in this case, the user actually wins. 105 00:08:35,950 --> 00:08:41,140 Now, if we're thinking from the perspective of the user when they're playing this game, then they 106 00:08:41,140 --> 00:08:47,430 don't really care if the computer won or the user won. They want to know, did they win or did they lose? 107 00:08:47,890 --> 00:08:50,080 So let's change this wording a little bit. 108 00:08:50,350 --> 00:08:54,930 We'll say, instead of user wins, we'll say you win. 109 00:08:56,020 --> 00:09:00,730 And if the computer wins, then we'll say you lose. 110 00:09:01,690 --> 00:09:10,510 So now if we run our program and test it out, so let's say I'm going to type 0 for rock and the 111 00:09:10,510 --> 00:09:14,590 computer chooses 2, but we actually get an error. 112 00:09:14,740 --> 00:09:22,770 It tells us that the greater than comparison is not supported between instances of int and string. 113 00:09:23,200 --> 00:09:24,100 What's going on here? 114 00:09:24,310 --> 00:09:32,830 Well, remember that we get our inputs as a number, but the input is always going to be a string. 115 00:09:33,340 --> 00:09:34,900 So if we want this to be a number, 116 00:09:34,900 --> 00:09:37,910 then we're going to have to wrap it inside an int. 117 00:09:38,500 --> 00:09:41,020 So now we turn it into a whole number. 118 00:09:42,070 --> 00:09:43,880 Now, this might be a good point to address 119 00:09:43,900 --> 00:09:49,950 well, what should happen if they typed something that wasn't 0, 1 or 2, whether they typed 34? 120 00:09:50,440 --> 00:09:52,780 Well, then naturally they should probably lose, 121 00:09:52,780 --> 00:09:53,070 right? 122 00:09:53,290 --> 00:10:01,060 So we can add an else statement addressing this situation. So we could say else we just print 123 00:10:01,360 --> 00:10:04,310 You typed an invalid number. 124 00:10:05,020 --> 00:10:07,480 You lose. Cool. 125 00:10:07,540 --> 00:10:08,690 So that sorts that out. 126 00:10:09,100 --> 00:10:13,060 Now let's run our code again and see if it works. 127 00:10:13,270 --> 00:10:13,990 What do you choose? 128 00:10:13,990 --> 00:10:15,130 Type 0 for Rock. 129 00:10:15,160 --> 00:10:16,440 I'm going to choose rock again. 130 00:10:16,960 --> 00:10:21,970 Computer chose zero and it tells me that you typed an invalid number. 131 00:10:22,960 --> 00:10:26,000 Well, actually, zero is not an invalid number. 132 00:10:26,020 --> 00:10:27,280 So what's going on here? 133 00:10:27,820 --> 00:10:30,930 Well, it's because it didn't fit this criteria. 134 00:10:31,630 --> 00:10:32,830 So I had zero, 135 00:10:32,830 --> 00:10:39,530 computer had zero, and it didn't fit this criterion because zero is not greater than zero. 136 00:10:40,000 --> 00:10:43,720 So it basically defaulted to the final else statement. 137 00:10:44,440 --> 00:10:48,350 But what's actually happening here is that that was a draw. 138 00:10:48,940 --> 00:10:50,050 Computer chose rock, 139 00:10:50,050 --> 00:10:50,940 I chose rock. 140 00:10:51,100 --> 00:10:55,840 That's a draw in the official rules of Rock Paper Scissors. 141 00:10:56,620 --> 00:10:58,660 So how do I catch that? 142 00:10:58,690 --> 00:11:05,650 Well, I could create another elif statement which says, well, if the computer_choice is equal to 143 00:11:05,650 --> 00:11:08,610 the user_choice, well, then we're going to print 144 00:11:09,520 --> 00:11:10,690 it's a draw. 145 00:11:12,130 --> 00:11:17,680 Now, let's test our app again and see if there are any other situations where our code is not behaving 146 00:11:17,680 --> 00:11:18,250 properly. 147 00:11:19,030 --> 00:11:23,350 I'm going to choose rock again, computer chose rock as well. 148 00:11:23,560 --> 00:11:26,150 And I guess it's a draw, so that's pretty good. 149 00:11:27,850 --> 00:11:33,970 Now, if I choose 0 and the computer chose 2, then this is going to be the statement that gets 150 00:11:33,970 --> 00:11:35,830 triggered and I win. 151 00:11:35,980 --> 00:11:37,030 So that's pretty good. 152 00:11:37,960 --> 00:11:44,030 Now, what if I chose 2 for scissors and the computer chose 0? 153 00:11:44,980 --> 00:11:48,270 Well, in this case, rock beats scissors 154 00:11:48,280 --> 00:11:50,770 so it should actually say I lose. 155 00:11:51,310 --> 00:11:54,250 But instead it says you typed an invalid number. 156 00:11:54,640 --> 00:12:02,260 So it defaulted to the else statement again because this particular situation is not caught by any of 157 00:12:02,260 --> 00:12:03,070 these statements. 158 00:12:03,940 --> 00:12:05,590 So what do we have to do instead? 159 00:12:06,070 --> 00:12:15,250 Well, we actually need another elif to say, well, if the computer_choice was equal to 0 and 160 00:12:15,250 --> 00:12:21,510 the user_choice was equal to 2, well, this means that rock beats scissors 161 00:12:21,760 --> 00:12:25,480 so I lose and the computer wins. 162 00:12:26,320 --> 00:12:30,040 Now, the final one that we need to catch is this case. 163 00:12:30,640 --> 00:12:39,430 If I type 1 for paper and computer chooses 0 for rock, it again defaults to the else statements 164 00:12:40,120 --> 00:12:43,870 whereas in fact in this case it should tell me that I won. 165 00:12:44,500 --> 00:12:45,820 So what's missing here? 166 00:12:46,090 --> 00:12:49,740 Well, it's the partner to this particular statement. 167 00:12:50,350 --> 00:12:54,360 If computer_choice is greater than user_choice then I lose. 168 00:12:54,700 --> 00:13:02,680 But on the other hand, if the user_choice was greater than the computer_choice, then I actually should 169 00:13:02,680 --> 00:13:03,070 win. 170 00:13:05,730 --> 00:13:15,480 So now the final thing we might have to fix is this else statement now actually never gets called because 171 00:13:15,480 --> 00:13:16,980 this is what happens. 172 00:13:17,430 --> 00:13:20,460 So let's say that I choose 456. 173 00:13:20,910 --> 00:13:23,730 It tells me that computer chose 2, I win. 174 00:13:24,060 --> 00:13:24,930 What's happening here? 175 00:13:24,960 --> 00:13:29,970 Well, it's actually this particular line that's being carried out. 176 00:13:29,970 --> 00:13:32,320 user_choice is greater than computer_choice. 177 00:13:32,820 --> 00:13:34,080 This is not what we want. 178 00:13:34,090 --> 00:13:35,910 We want it to default to 179 00:13:36,210 --> 00:13:37,650 You typed an invalid number. 180 00:13:37,650 --> 00:13:42,690 You lose. So we can actually just use else in this situation. 181 00:13:43,260 --> 00:13:45,540 We actually need to provide a condition. 182 00:13:46,380 --> 00:13:54,610 We're going to use elif to check if the user_choice is greater or equal to three, 183 00:13:55,500 --> 00:13:59,910 now, the computer will never choose anything other than 0, 1 and 2 184 00:13:59,910 --> 00:14:01,530 so we don't have to check that one. 185 00:14:01,800 --> 00:14:06,230 But the user could choose something above 3 or below 0. 186 00:14:06,450 --> 00:14:14,530 So we can use an or statement to catch this. Or if the user_choice is less than zero, 187 00:14:15,180 --> 00:14:18,900 well, in this case, you typed an invalid number, you lose. 188 00:14:19,740 --> 00:14:22,110 But that's not all that we have to do. 189 00:14:22,410 --> 00:14:29,760 If we hit run and we again type some extraordinarily large number, you'll see that it still says 190 00:14:29,760 --> 00:14:31,230 computer chose 1. 191 00:14:31,230 --> 00:14:32,040 You win. 192 00:14:32,520 --> 00:14:33,240 What's going on? 193 00:14:33,240 --> 00:14:39,290 We have this statement that should catch this situation, but it's right at the bottom. 194 00:14:39,510 --> 00:14:44,370 So it's not going to be checked until one of the previous ones are checked. 195 00:14:44,880 --> 00:14:48,720 Namely, it's one of these that's going to be the problem. 196 00:14:49,260 --> 00:14:57,240 So what we have to do is we have to move this statement above all the lines so that we first check if 197 00:14:57,240 --> 00:15:02,390 the user_choice is greater than three or less than zero. 198 00:15:03,060 --> 00:15:08,850 And if that's not true, do we actually continue checking to see who won the game. 199 00:15:09,750 --> 00:15:16,830 Now, finally, we can run our code type an invalid number and get you typed an invalid number. You lose. 200 00:15:18,120 --> 00:15:24,600 So now that we've actually got our logic all sorted out, the next step is to include our images. 201 00:15:25,320 --> 00:15:29,340 And to do that, we have to somehow match it up with these numbers we have, 202 00:15:29,340 --> 00:15:30,870 right? 0, 1 and 2. 203 00:15:31,590 --> 00:15:36,870 Now, there's many, many ways that you could do this and you could solve this project. 204 00:15:37,230 --> 00:15:45,540 But the easiest way is probably putting the game images into a list where we have rock as the first 205 00:15:45,540 --> 00:15:50,170 one, paper as the second one and scissors as the last one. 206 00:15:50,640 --> 00:15:58,410 So we're using the fact that lists have a order that is always going to be followed. So we can now get 207 00:15:58,410 --> 00:16:02,060 hold of the rock picture by getting game_images[0]. 208 00:16:02,400 --> 00:16:09,570 We can get scissors by doing game_images[2] and so on and so forth. And we can match those up to our 209 00:16:09,570 --> 00:16:12,210 choices, the user_choice and the computer_choice. 210 00:16:12,810 --> 00:16:20,790 So when the user chooses a number, then we're going to print from the game_images and we're going to 211 00:16:20,790 --> 00:16:26,340 use our little square brackets to select the image we want from this list. 212 00:16:26,790 --> 00:16:31,140 And the one that we want is going to be based on the user's choice, right? 213 00:16:31,320 --> 00:16:33,630 0 for rock, 1 for paper, 2 for scissors. 214 00:16:33,960 --> 00:16:42,600 So we're going to put user_choice as the index to pick out an image from game_images. Now down here for 215 00:16:42,600 --> 00:16:49,950 the computer_choice, instead of printing the number that the computer chose, I'm going to delete that 216 00:16:49,950 --> 00:16:51,480 and add a little colon. 217 00:16:52,680 --> 00:16:56,550 So that way it's going to show computer chose 218 00:16:56,910 --> 00:17:02,130 and then I'm going to print the image of the choice that the computer made. 219 00:17:02,520 --> 00:17:04,290 So I'm going to add another print statement, 220 00:17:04,560 --> 00:17:10,890 I'm going to tap into the game_images and then inside some square brackets, I'm going to use the computer 221 00:17:11,130 --> 00:17:17,820 choice which is going to be between 0, 1 and 2 as the index to pick out the corresponding image 222 00:17:18,180 --> 00:17:20,340 from my list game_images. 223 00:17:20,930 --> 00:17:28,170 So now we're finally ready to run our code and I'm going to choose 0 for rock and the computer chose 224 00:17:28,170 --> 00:17:28,920 paper. 225 00:17:29,220 --> 00:17:31,920 So paper beats rock, I lose. 226 00:17:32,790 --> 00:17:33,840 Let's try this again. 227 00:17:33,840 --> 00:17:37,860 I'm going to choose scissors and computer chose scissors. 228 00:17:37,860 --> 00:17:42,090 It's a draw. But we have also introduced a bug. 229 00:17:42,690 --> 00:17:47,730 So if we test this using a number that's outside of this range, 0, 1 or 2, 230 00:17:47,730 --> 00:17:51,330 so let's try 5. And we hit enter, 231 00:17:51,330 --> 00:17:52,020 what do we get? 232 00:17:52,050 --> 00:17:53,970 We get a index error. 233 00:17:54,480 --> 00:17:56,110 So what has happened here? 234 00:17:56,250 --> 00:17:58,680 Well, this is up to you to debug. 235 00:17:59,070 --> 00:18:02,970 Well, this is a really good opportunity for you to practice your debugging. 236 00:18:03,300 --> 00:18:04,620 So think about what has 237 00:18:04,730 --> 00:18:12,280 changed since the last time we tested this and how you can fix the code so that it works as expected, 238 00:18:12,590 --> 00:18:18,290 so telling us that you typed an invalid number, you lose whenever we type a number that's above or 239 00:18:18,290 --> 00:18:20,360 equal to three or less than zero. 240 00:18:20,840 --> 00:18:25,880 So I want you to pause the video and see if you can debug this challenge so that when you type in 5, 241 00:18:26,090 --> 00:18:29,330 you get this printed. Pause video now. 242 00:18:32,680 --> 00:18:39,070 All right, so what's going on here, because we tested this and it worked, but in between that time, 243 00:18:39,070 --> 00:18:46,480 we also added this line because we wanted to get a hold of the game images based on the user's choice. 244 00:18:46,930 --> 00:18:51,490 Now, at this point, the user's choice is unchecked by the if statement. 245 00:18:51,850 --> 00:18:56,110 So it could still be equal to 4 or 5 or 10 or a million. 246 00:18:56,560 --> 00:19:04,300 So if in that case, it tries to get hold of the fifth image from the game_images list, well, it doesn't 247 00:19:04,300 --> 00:19:04,690 exist. 248 00:19:04,810 --> 00:19:06,850 There's only 0, 1 and 2. 249 00:19:07,750 --> 00:19:14,500 So to fix this, we need to move this if statement so that it gets checked before this line of code 250 00:19:14,500 --> 00:19:15,370 gets carried out. 251 00:19:15,940 --> 00:19:22,330 So let's go ahead and cut this line of code out and put it right above this print statement. 252 00:19:22,840 --> 00:19:30,340 So in this case, if the user types in a choice that's above or equal to three or less than zero, 253 00:19:30,670 --> 00:19:32,020 we're going to print this. 254 00:19:32,440 --> 00:19:38,670 But else, if they typed in any other number, then we want the rest of the code to continue. 255 00:19:39,010 --> 00:19:44,070 So let's select the rest of the code, hit tab and tab it over 256 00:19:44,080 --> 00:19:46,510 so that is included under the else statement. 257 00:19:47,050 --> 00:19:54,010 Now let's go ahead and change this from elif just to an if because we're no longer checking it as another 258 00:19:54,010 --> 00:19:54,430 else- 259 00:19:54,430 --> 00:19:56,890 if statement. It is just a straight up 260 00:19:56,890 --> 00:20:05,590 if. So, in this case, if they typed a 5, then it will go into this basket and it will finish there. 261 00:20:05,890 --> 00:20:10,670 But otherwise, it will go into this basket and it will continue checking later on. 262 00:20:11,260 --> 00:20:14,570 So did you manage to debug your code and figure out the issue? 263 00:20:15,040 --> 00:20:17,320 This is one of the most important skills 264 00:20:17,320 --> 00:20:21,760 as a programmer. You have plenty of opportunities coming up to practice your debugging. 265 00:20:22,330 --> 00:20:27,790 And if you ever want more practice, head over into the Q&A and see what other students have issues 266 00:20:27,790 --> 00:20:31,810 with and see if you can help them out by practicing your debugging skills. 267 00:20:32,590 --> 00:20:40,570 Now, we have completed the project by using everything from lists to randomization to variables to 268 00:20:40,570 --> 00:20:43,370 if statements and a whole lot of logic. 269 00:20:43,630 --> 00:20:47,660 So how did you get on with this project? If you struggle 270 00:20:47,680 --> 00:20:54,970 this is the time again to go back to it and maybe map things out using a flow diagram or try to run 271 00:20:54,970 --> 00:20:59,080 the code using Thonny to see how it does it step by step. 272 00:20:59,590 --> 00:21:04,180 But the important thing is that you got to write your own code and you got to make it work. 273 00:21:04,420 --> 00:21:09,580 And this is the only way that you'll understand what's going on so that you can continue on. 274 00:21:09,910 --> 00:21:15,670 And as things get harder, you'll be able to learn more because you've already understood all of the 275 00:21:15,670 --> 00:21:16,570 previous knowledge. 276 00:21:17,320 --> 00:21:19,150 So I hope you had fun with me today 277 00:21:19,150 --> 00:21:24,550 learning and building, and hopefully I will see you tomorrow bright and early. 278 00:21:24,880 --> 00:21:27,100 So that's good night from me for today. 29198

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.