Contents
This notebook is based on "Think Python, 2Ed" by Allen B. Downey
https://greenteapress.com/wp/think-python-2e/
=
) and an equality test (==
)
In [1]:
a = 5
b = a # a and b are now equal
a = 3 # a and b are no longer equal
In [2]:
#x = x + 1 # Generates an error
x = 0
x = x + 1 # Works properly now
In [3]:
def countdown( n ):
while( n > 0 ):
print( n )
n = n - 1
print( 'Blastoff!' )
countdown( 5 )
n > 0
is trueboolean
variablefor
or while
loop, there are generally differences in how they are usedfor
loop can be referred to as a definite loopwhile
loop can be referred to as an indefinite loop
In [4]:
def echo():
while( True ):
line = input( '> ' )
if( 'done' == line ):
break
print( line )
print( 'Done!' )
break
statements can be useful, be careful
In [5]:
def start_guessing( low, high ):
# INSERT YOUR CODE HERE
print( 'Correct!' )
n
as an argument and return the sum.
In [6]:
def sum_squares( n ):
# INSERT YOUR CODE HERE
return 0
In [7]:
def double_money( days ):
# INSERT YOUR CODE HERE
return 0