Python for Absolute Beginners Transcripts
Chapter: Error handling
Lecture: Where are the invalid numerals
0:00 Well, let's fix this crashing program
0:02 that we've got going on here.
0:04 Notice we're over in error handling, rps error handling.
0:07 This is in CH11 in the GitHub repository.
0:11 And I've already sort of set this up a little bit for us.
0:13 We've got the rpsgame, and it should look really familiar.
0:17 Except for there's a few issues
0:18 we're going to solve that in a second
0:19 but this starts up and it's going to say
0:21 Oh, not external libraries but error handling addition.
0:25 So what we've done is we've taken
0:26 the external libraries edition, CH10
0:29 and we've copied it over with some small changes.
0:32 Remember the way it worked before is
0:34 we gave it that cool dropdown thing
0:36 where it could figure out what, you know
0:38 what you're starting to type like a
0:40 Oh do you want to type error
0:41 and it would just complete that for us.
0:43 We've fallen back in a bit in our get roll here.
0:47 Where we're going to get the input from the user
0:50 and we're converting it to an integer again.
0:52 Specifically 'cause that's a super easy way
0:54 for us to crash the program.
0:55 Now, notice there's some requirements that are
0:57 here we got to install from our requirements file.
1:00 There's a couple of options.
1:01 We can click this button, and that's great
1:04 or we can come down here.
1:05 Make sure your virtual environment is active
1:08 and you can say, pip install -r
1:10 requirements.txt and it'll complete that for us.
1:14 Cool, now we should be able to run this program.
1:16 We don't care about this extension for
1:18 the requirements.txt.
1:20 A lot of the extensions in PyCharm are awesome.
1:22 They've got great ones for like, CSVs
1:24 and Nginx files, and all kinds of stuff.
1:25 But for some reason the requirement one
1:27 messes with that little dialogue
1:29 that you just saw there, that yellow bar
1:31 so I don't use it.
1:32 Anyway, we're ready to run our game here.
1:34 Let's see that it works.
1:35 Let's see that everything is working good.
1:37 Yes, my name is Michael, or is it Crash Bandit?
1:40 Okay, seven, yeah, not so much.
1:43 That's not great. But one thing that's cool about PyCharm
1:45 is when you do have an error
1:46 notice over here on the right you can see
1:49 the various places where this is happening
1:51 and we can just click right here
1:53 and yeah bump that down a little bit
1:56 and it takes us right to the line where
1:58 the error first happened.
1:59 Well, here's where the error is.
2:01 So you can see what's going on.
2:03 We're passing in seven as like this
2:06 and it really wants us to pass in that
2:09 the numeral 7, but it's not going to happen, is it?
2:12 So it's this error right here, and in fact
2:14 we can sort of guard against this whole bit right there
2:18 to make sure that everything is working correctly.
2:20 We'll see how to do that next.