Python for the .NET Developer Transcripts
Chapter: The Python Language
Lecture: C# function basics

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The next area that I want to focus on for you is functions. So, we've already really sort of been using functions in Python.
0:09 You saw we've had our main method and our some_method and took an argument, but I want to focus specifically on what are the parameters, what can we do
0:18 in terms of flexibility, return values and all sorts of stuff like that. Method overloading, and so on.
0:25 So we're going to write, at the first start exploring this we're going to write a little game, it'll be a lot of fun.
0:30 And then we're going to come back and focus on specifically on, method overloading type of operations. So here we have a program in C#.
0:39 And let's just run it, I think you'll enjoy. It's a high low game, so it says I'm thinking of a number between one and 100, how many steps
0:48 can you guess it in, what number am I thinking of? This is where you apply your binary search algorithm 50 too low, 75 too low 90 too high, 85 too high
1:00 80, 76, 77, 78, 79 it must be. There it is, of course, I was thinking of 79. Well, my little binary search didn't work that well
1:12 and I kind of broke down there when I got to the 70s but nonetheless, we're going to write this program in Python
1:18 it does things like go and get the guess from the person and so on. So, it should be a lot of fun let's just really quickly look at the code here
1:25 before we go talk about it in Python. So here's our main method. We've run it and it says ShowHeader that's the big little printed bit at the top there
1:35 that says, Welcome to the High Low Game. We create a random number generator and we get a random integer between one and a hundred.
1:43 And then we also keep track of how many times this happened. So when I go through, want to get a guess if they don't give us a guess
1:50 it's a knowable editor, if they don't give us a guess then we could just tell them, hey, no, you've got to give us
1:55 a number, ask 'em again, something like that. Count how many times they give us real guesses and evaluate the guess, right here we're passing
2:01 the value of that knowable type in the number and then if they get it right they break and we say, good job, you did this many times, all right.
2:09 So pretty standard C# down here, easy six lines for what it's worth. We'll want to come back and look at this in Python as well.
2:16 All right, so this is the game that we're going to recreate over in Python to explore working with the functions.

Talk Python's Mastodon Michael Kennedy's Mastodon