13.3. Fortune Teller¶
You can tell someone’s fortune by having them pick a number and then using if
statements to print the fortune for the number.
- 1
- It would have to at least check if it was 1 or 2.
- 2
- It executes every if, even if it already found the answer.
- 5
- It executes every if.
- 6
- There are only 5 logical expression here so it can't be more than 5.
How many conditions (logical expressions) are checked if the user answered 2?
- 1
- It has to execute each if in order from top to bottom.
- 2
- How would this work?
- 5
- It executes every if.
- 6
- There are only 5 logical expression here so it can't be more than 5.
How many conditions (logical expressions) are checked if the user answered 6?
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
Modify the program to handle when the user enters something other than a number from 1 to 5. Also add some additional fortunes and allow the user to pick a number from 1 to 10.