CMPT 120 Lecture 18: CMPT120 – Lecture 18

59 views2 pages
meghan78 and 39786 others unlocked
CMPT 120 Full Course Notes
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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents