Calvin (Deutschbein)
W6Mon: 29 Sep
def is_divisible_by(x, y):
if x % y == 0: # just return here instead of 'if'
return True
else:
return False
if is_divisible_by(i,7) == True: # remove '== True'
print(i)
def embiggen():
x = 2
x = x + 2
return
x = 1
print("Before:", x)
embiggen()
print("After:", x)
x = 1
Before: 1
After: 1
def Vegas(x): # what happens in Vegas etc etc
y = 2
for i in range(3):
print("Vegas: i = ",i,"| x = ",x,"| y = ",y)
x += y
return x
x = 3
z = Vegas(x)
print("Mine: x = ", x, "| z = ", z)
Vegas: i = 0 | x = 3 | y = 2
Vegas: i = 1 | x = 5 | y = 2
Vegas: i = 2 | x = 7 | y = 2
Mine: x = 3 | z = 9
print(2 + 2) # same as print(4)
print(2 + 2) # same as print(4)
def double_print(str):
print(2 * str)
double_print("mur") # same as print(2 * "mur")
print(2 + 2) # same as print(4)
double_print("mur") # same as print(2 * "mur")
def print_n_times(x, str):
# n is 2, not 3, because "my n" and "double print n" differ
print(x * str)
n = 3
print_n_times(2, "mur") # same as print(2 * "mur")
print(2 + 2) # same as print(4)
double_print("mur") # same as print(2 * "mur")
n = 3
print_n_times(2, "mur") # same as print(2 * "mur")
def repeat_n_times(x, str):
return x * str
s = repeat_n_times(2, "mur") # same as s = 2 * 'mur'
print(s) # prints "murmur"
def no_duplicates(word):
for i in range(len(word)):
if word[i] in word[:i]:
return False
return True
def no_vowels(word):
for letter in word:
if letter in "aeiou":
return False
return True
def longest_which_funcs(func):
candidate = ""
for word in ENGLISH_WORDS:
if len(word) > candidate and func(word):
candidate = word
return candidate
print(no_duplicates("aorta"))
print(no_vowels("why"))
print(longest_which_funcs(no_duplicates))
print(longest_which_funcs(no_vowels)) |
False
True
ambidextrously
glycyls
|