Should we worry about being grammatically correct in outputs? For example, the Old Macdonald function.
You should definitely be syntactically correct for Python in your outputs. English grammar is more flexible.
Tbh I still don't 100% get what the return thing does
The return
line in a function gives a value back and stops the execution of the function. We'll see some more examples on Monday.
Where do returned values go?
They go to wherever your code has instructed Python to put them. It's possible to do nothing with them, or to use them in a variable assignment so that the returned value is now stored in the variable.
Why must the variables in functions other than the main() function have different names than the inputs of the main() function?
This is a style and clarity choice. It will be much easier for you to debug your programs and figure out what is going on if the variables have different names in different scopes.
Why isn't the main() function written first?
The structure we've been using in our Python programs defines all the functions first, then tells Python to start executing the main()
function. We could have the function definitions in a different order, but --- again as a style choice --- we usually put the main
function last. (This makes it easier to find, once the programs include more lines than can be seen on the screen at one time.)
Do you have to have all the functions defined in the same file?
Nope! We've seen already how to use functions defined in other files, for example import math
and import random
. We'll eventually use this in our programs, but for now we are starting with the easier situation where all the functions we write appear in the same file.