CMPT 120 Lecture 18: CMPT120 – Lecture 18
meghan78 and 39786 others unlocked
29
CMPT 120 Full Course Notes
Verified Note
29 documents
Document Summary
2 components of recursive function: base case, function itself. When a recursive function calls itself, what must me make sure of: must have a base case, must change its state and move toward the base case. Issue with the code (see slide: semantic error, adding to itself infinitely, will always be over 0. Simplier recursion: tree maker: main parameter is the level, to change the colour, you must change it in the base case. A function that returns something: fruitful functions (creates some sort of value, you can assign it to a variable or just randomly print random. choice is a fruitful function. More on while loops: not function, you can concatenate 2 lists together, just like with strings, this is extra useful when using while loops, must add like items. Can you use while to validate input? yes. Use a plus sign, but they must be 2 lists.