Python for Absolute Beginners Transcripts
Chapter: Code that interacts with users
Lecture: Practice time!
0:00 It's time for some practice exercises.
0:02 So again, the easiest way to get to the GitHub Repository
0:05 just go to the course page and click right there.
0:08 We're going to go down to our practices
0:11 and now we're in chapter five, interactive code.
0:14 So let's see what I've put on deck for you here.
0:17 The idea is work on these, but don't let them drag you down.
0:20 Don't get stuck.
0:21 Don't stop going to the class
0:23 and for some reason, you do get stuck there
0:25 we talked about how to get help
0:26 at the beginning of the course.
0:28 All of those things but eventually move on if you get stuck
0:31 but here's the idea.
0:32 I'm going to cover a couple of core concepts
0:34 how do you run Python code, not in the REPL
0:37 but execute a Python source file
0:39 so we talked about that and it's up there
0:41 if else statements, here's some examples for those
0:44 also while loops, you're going to need both of those
0:47 in the exercises.
0:48 Something we haven't spoken about
0:49 but is really interesting and common in programming
0:53 is actually working with the remainder.
0:56 Turns out this is more useful in programming
0:58 than it is in, like, regular life
1:00 so we all know about remainders
1:02 like if you do whole number divisions say like
1:04 19 divided by 5
1:07 well that's like, 3.8
1:09 but in whole number division
1:11 it's three with four left over, right
1:14 so there's a way in programming in Python
1:17 to say, give me the remainder of this division
1:20 so 19 %, modulus, mod, 5
1:24 with the remainder which is four.
1:26 The reason we need this is, in the exercises I ask you
1:28 to work with even numbers, and this is how you check
1:31 if something is even, right there.
1:33 Now you have those as reference to work from
1:36 what are the exercises?
1:37 First one, here we go again, hello world.
1:40 Idea is just to create helloworld.py
1:43 a file that prints out hello world like we did before
1:46 but now just make sure that you can execute a python file
1:50 right, so there's some examples above
1:52 if you do this in PyCharm that's easy
1:54 there's some notes here on how to do that.
1:56 You're not using PyCharm there's also some notes above
1:58 on how to run it.
2:00 Next, write a program that requests a number from a user
2:04 and then print out whether or not it's even or odd.
2:07 So, that's simple, and then you can extend that program
2:10 in the next exercise, here
2:13 to continue to ask that question
2:16 as long as they provide a non-zero number.
2:18 So if they provide 27, say odd
2:20 if they provide 90, say even
2:22 but if they provide zero, say goodbye and stop the program
2:26 exit the program nicely.
2:29 Right, so that's the idea
2:30 and then pick one of these ideas over here
2:32 and visualize it at http://www.pythontutor.com.
2:36 Alright, well that's the exercises for you
2:39 be sure to practice them, also if you'd like
2:41 go ahead and go through the example we did in the videos
2:45 remember the example that we did is up here
2:48 we go back into code, here
2:52 Vector five, that's the M&M game
2:55 without going exactly through this source code here
2:58 why don't you go and try to recreate this little M&M game
3:01 or some variation on it for yourself
3:03 using just the stuff that we saw back here
3:08 with some of these core concepts and what not.
3:10 That's one more thing to throw in there
3:11 for you to practice and hopefully you get good
3:14 at if statements, while loops
3:16 and making code decide things.