Python Homework Help
Python Homework Help
Problem 1
2.False. You may end up jumping back and forth between the
same two forever, given an S-shaped function (draw a
diagram).
3.False. mydict[somekey] = somevalue.
4.False. Precision is finite.
5.False. Recursion may be a more natural way to express
certain problems (e.g.: fib, Towers of Hanoi).
6.True. Code reuse.
7.True. A quick lookup.
Problem 2
1.Yes, they return the same value for all possible inputs (at least
of the types that we’ve learned about so far in class).
2.No, they print different things for negative inputs. This is
because a and b are updated to refer to a different number in
compare1, whereas they are not updated in compare2.
Note about this function: it is a bit strange in that it handles
multiple argu ment types.
1. f(2112) returns 2+1+f(’12’) ==> 2+1+1+2 ==>
2.
6. Given an integer or a string representation of an integer, f
returns the sum of its digits.
Problem 4
def nuggets(num):
for a in range(num/6+1):
for b in range(num/9+1):
for c in
range(num/20+1):
i f 6*a + 9*b + 20*c ==
num: return True
return False
Problem 9