Python for Absolute Beginners Transcripts
Chapter: Organizing and reusing code with functions
Lecture: Practice time!

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now that you've seen the power of functions
0:01 both for re-using code allowing you to work on it
0:04 in one place but affect it in many places that it's used
0:07 in your program and treated as a black box.
0:11 Just, here's a core idea that may be complicated but
0:14 all you got to think about is what goes in
0:16 and what comes out, for example, check for winning throw.
0:18 That was super complicated, but we just passed in the plays
0:22 and got the winner back.
0:23 That was nice so let us think about our program
0:26 in a much higher level.
0:28 So, I put together some practice exercises
0:30 for this chapter, as well.
0:31 I think you'll have a lot of fun wit this one.
0:33 A pair of core concepts that are very close to each other
0:36 and that's just about creating functions.
0:37 Here's a function that takes a parameter and uses it.
0:41 Here's a function that has a return value
0:44 it gets the data internally creates it
0:46 and then gives it back.
0:47 And we can even use these together
0:49 like we can use the get name one to actually get the name
0:51 and then to say hello to greet the person after they've
0:54 given us their name.
0:55 So, here's a couple ways in which we can do that.
0:58 For this exercise, your job is to take
1:00 the M&M guessing game which you'll recall
1:03 it was written with no functions
1:05 just all jammed together created back in CH05
1:08 before we talked about functions.
1:10 And clean it up, using functions.
1:12 Now, if you look in this folder
1:14 in practices, CH06.
1:16 You can see there's a copy this.
1:17 I put it here just to make sure that it's right here
1:20 and easy to get to.
1:22 If you go here, you can see
1:23 it's doing things like printing out what the game is
1:25 some information.
1:27 Getting some random details.
1:29 Playing some rounds, checking for a winner.
1:32 These should all sound kind of familiar.
1:34 And you could use functions to make it a lot nicer.
1:36 So, that's your job, take this code
1:38 make a copy of it somewhere
1:40 make it better with functions.