1
2
3
None None
def square_it(x): x*x
4
None None
def square_it(x): x*x
None
square_it(4)
4
None None
def square_it(x): x*x
None
square_it(4)
None
sixteen = square_it(4)
sum = sixteen + 4 # TypeError!
4
print()
print(-2)
f = open(‘songs.txt’, ‘w’)
f.write(“Dancing On My Own, Robyn”)
f.close()
5
def square_num1(number): return pow(number, 2)
def square_num2(number): print(number ** 2)
6
def square_num1(number): return pow(number, 2)
def square_num2(number): print(number ** 2)
6
def square_num1(number): return pow(number, 2)
def square_num2(number): print(number ** 2)
None
6
7
None
7
print(print(1), print(2))
8
print(print(1), print(2))
print(print(1), print(2))
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
def print()…
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
def print()…
1
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
def print()…
1
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
def print()…
1
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1) print(2)
def print()…
1
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
print(2)
def print()…
def print()…
1
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
print(2)
def print()…
1
def print()…
2
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
print(2)
def print()…
1
def print()…
2
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
print(2)
def print()…
1
def print()…
2
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
print(2)
def print()…
1
def print()…
2
8
print(print(1), print(2))
print(print(1), print(2))
def print()…
print(1)
print(2)
def print()…
1
def print()…
2
8
9
def calculate_dog_age(human_years, multiplier = 7): return human_years * multiplier
calculate_dog_age(3)
calculate_dog_age(3, 7)
calculate_dog_age(3, 6)
calculate_dog_age(3, multiplier=6)
10
def divide_exact(n, d): quotient = n // d remainder = n % d
return quotient, remainder
q, r = divide_exact(618, 10)
11
def divide_exact(n, d): “””
>>> q, r = divide_exact(2021, 10)
>>> q
202
>>> r
1
“””
quotient = n // d remainder = n % d
return quotient, remainder
12
13
True False
avoid_highways = True
personalized_ads = False
14
passed_class = grade > 65
wear_jacket = is_raining or is_windy
15
32 == 32
30 != 32
60 >= 32
60 >= 32 32 >= 32 20 < 32
20<32 32<=32
⚠= ==
16
and 4 > 0 and -2 < 0
True
False False
or 4 > 0 or -2 > 0
True False
True False
not not (5 == 0)
17
may_have_mobility_issues = (age >= 0 and age < 2) or age > 90
18
def passed_class(grade): return grade > 65
def should_wear_jacket(is_rainy, is_windy): return is_rainy or is_windy
19
20
21
name = ‘sosuke’
greeting = ‘ahoy, ‘ + name
def greet(name):
return ‘ahoy, ‘ + name
return ‘ahoy, ‘ + name
22
…
…
23
…
…
23
…
…
23
…
…
23
…
…
24
…
…
24
25
if
…
clothing = “shirt”
if temperature < 32: clothing = "jacket"
26
elif
if
…
elif
…
elif
…
clothing = “shirt”
if temperature < 0: clothing = "snowsuit"
elif temperature < 32: clothing = "jacket"
27
else
if
…
elif
…
else
…
if temperature < 0: clothing = "snowsuit"
elif temperature < 32: clothing = "jacket"
else:
clothing = "shirt"
28
if num < 0:
sign = "negative"
elif num > 0:
sign = “positive”
else:
sign = “neutral”
if elif
else
29
30
def get_number_sign(num): if num < 0:
sign = "negative" elif num > 0:
sign = “positive” else:
sign = “neutral” return sign
get_number_sign(50) # “positive”
get_number_sign(-1) # “negative”
get_number_sign(0) # “neutral”
31
def get_number_sign(num): if num < 0:
return "negative" elif num > 0:
return “positive” else:
return “neutral”
get_number_sign(50) # “positive”
get_number_sign(-1) # “negative”
get_number_sign(0) # “neutral”
32
33
34
while
multiplier = 1
while multiplier <= 5:
print(9 * multiplier)
multiplier += 1
35
total = 0
counter = 0
while counter < 5:
total += pow(2, 1)
counter += 1
total = 0
counter = 0
while counter < 5:
total += pow(2, counter)
counter += 1
36
counter = 1
while counter < 5:
total += pow(2, counter)
37
counter = 1
while counter < 5:
total += pow(2, counter)
counter += 1
37
counter = 1
while counter < 5:
total += pow(2, counter)
counter += 1
counter = 6
while counter > 5:
total += pow(2, counter)
counter += 1
37
counter = 1
while counter < 5:
total += pow(2, counter)
counter += 1
counter = 6
while counter > 5:
total += pow(2, counter)
counter += 1
37
38
def sum_up_squares(start, end): counter = start
total = 0
while counter <= end:
total += pow(counter, 2)
counter += 1 return total
sum_up_squares(1, 5)
39
break
counter = 100
while counter < 200:
if counter % 7 == 0: first_multiple = counter break
counter += 1
40
counter = 100 while True:
if counter % 62 == 0: first_multiple = counter break
counter += 1
⚠
41
42
def is prime(n):
"""Return True iff N is prime.""" return n > 1 and smallest factor(n) == n
def smallest factor(n):
“””Returns the smallest value k>1 that evenly divides N.””” ???
def print factors(n):
“””Print the prime factors of N.””” ???
43