Computers appear to be smart and powerful because they make billions of repetitive decisions every second. In this section, you will learn about decisions (selection) and repetition.
Chapter 2: Control
Booleans are data that have values True or False, and that makes them useful for making decisions.
if Boolean-expression-I: suite-of-statements elif Boolean-expression-II: suite-of-statements else: suite-of-statements
while Boolean-expression: suite-of-statements
while Boolean-expression-I: suite-of-statements if Boolean-expression-II: break # Exit loop now; skip else if Boolean-expression-III: continue # Go to top of loop now suite-of-statements else: suite-of-statements # if we did not hit a break
Solve this puzzle substituting unique, non-zero integers for each letter:
HERE + SHE ----- COMES
Write a program that prints the numbers from 1 to 100. However, for multiples of three print "Fizz" instead of the number, and for the multiples of five print "Buzz." For numbers that are multiples of both three and five print "FizzBuzz."
How to count:
counter = 0 # start with an empty counter for i in collection: counter += i # increment counter