For each of the following functions, find values of
the parameters so that the functions will return True. You should assume
that x, y, and z are ints, and that s is a string. Hint: reason your
way through this. How you find your answer is just as
important, if not more so, than what the answer is! While you may
confirm your answer by running it in a Python interpreter, do not use the
Python interpreter at all when solving the problem. You will be given
similar problems such as these on written quizzes without access to Python
interpreters! Also, consider only the possible inputs. For example, if you
are given that x+y==16, since x>y>0, we only need consider (15,1), (14,2),
..., (9,7). That's only 7 (x,y) points in total, one of which must be
correct! Also, CIRCLE YOUR ANSWERS!
def f1(x, y):
return (100>x>y>0) and (x+y == 10) and ((x>>y)<<y == x)
def f2(x, y):
return ((100>x>y>0) and (y == x%10*10 + x/10) and
(x+y == 44) and (x%y == 5))
def f3(x, y):
return ((100>x>y>0) and (x/2+x**y == 100))
def f4(x, y):
return (100>x>y>0) and (x|y == x+y) and (x+y == 40)
def f5(x, y):
return ((100>x>y>0) and
(x+y == 10) and
(round(float(x/y)) != round(float(x)/y)))
def f6(x):
assert(10**2 > x > 10**0)
y = x
for z in xrange(x):
if (z % 7 == 0):
y += 1
return (y==21)
def f7(x):
assert(10**8 > x > 10**7)
y = 0
count = 0
while (x > 0):
if (x%10 == count):
y = 10*y + 1
elif (x%10 != 9):
break
else:
y *= 3
x /= 10
count += 1
return (y == 993111)
def f8(x,y,z):
ok = False
if (2*x > y > x > z):
ok = (x**2 == x^0b1010)
if (z/2 == 2*z):
ok = ok and (y%3 != y/2)
else:
ok = ok and (y == y+1)
return ok
def f9(x):
assert(10**2 > x > 10**1)
z = 1
y = 0
while (z < x):
z *= 2
y += 1
return ((z == x+1) and (y == x/6))
def f10(x):
assert(10**2 > x > 10**0)
y = 0
z = 0
while (z < 5):
y += 1
if (((y ^ 7) % 8) == 0):
z += 1
return (y == x)
def f11(x):
assert(10**3 > x > 10**2)
y = 0
z = 0
for w in xrange(23, 456, 7):
if (w % 2 == 0):
continue
elif (w % 5 == 0):
break
elif (z % 2 == 0):
z += 1
else:
z += (w % 10)
y += z
y *= 10
return (z == 9) and (x == y)
def f12(s):
i = s.upper().find("B")
assert(s[i] != "B")
assert(s.find(str(i)) == 2)
for k in xrange(len(s)/2):
assert(ord(s[k]) + 1 == ord(s[k+len(s)/2]))
return True
def f13(s):
assert (len(s) == 5)
t = 3*s[::2]
assert(s == t[:len(s)])
return (s != len(s)*s[0])
carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem