Changes between Version 68 and Version 69 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 4, 2017, 9:59:45 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v68 v69 269 269 Run this one. What does it output? A lovely happy birthday song for two kids? Now imagine if you had to write a program to print out a happy birthday for every single person in your grade without it. It'd get pretty ugly, fast. 270 270 271 `def` is used in Python to indicate a custom function, and you have to ''def''ine it in your program before you use it. It takes an argument of an age, and second argument of a list of names. The "singHappyBirthday" line actually ''calls''the custom function, with the two arguments it needs.272 273 A function can return a value , by using the Python keyword `return` as in:271 The keyword `def` is used in Python to indicate a custom function, and you have to ''def''ine it in your program before you use it. This function takes an argument of an age, and second argument of a list of names. The "singHappyBirthday" line at the end actually ''calls'' or runs the custom function, with the two arguments it needs. 272 273 A function can return a value too, by using the Python keyword `return` for example: 274 274 275 275 {{{ … … 285 285 }}} 286 286 287 Now your turn... Modify the 'That's-a big number" exercise above, adding a custom function called called inputNumber to input one number, and use it instead of repeating the while-not stuff. Much easier to read, no?287 Now your turn... Modify the 'That's-a big number" exercise above, adding a custom function called called inputNumber to input one number, and use it instead of repeating the while-not stuff. Run it and verify the output is the same. Much easier to read, no? 288 288 289 289 Here's the [[ThatsaBigNumberSolution|solution]]