====================================================================== Solutions to review questions: -------------- def neg_count(): answer = input("Enter a number: ") below = 0 while answer != "": if float(answer) < 0: #### added float(...) below += 1 answer = input("Enter a number:") print("Below: " + str(below)) #### added str(...) -------------- def my_startswith(s1, s2): n = len(s2) return s1[:n] == s2 -------------- # x contains some bool value True and x SHORTER: x # x contains some bool value False or x SHORTER: x y > 0 and y < 10 SHORTER: 0 < y < 10 (y > 0 and z == 1) or (y > 0 and z == 2) SHORTER: y > 0 and (z == 1 or z == 2) -------------- the picture looks roughly like this, but smaller: __________________ ________________ ______________ ____________ __________ ________ ______ ____ __ ------------ 7.5 (float) 7.5 (float) 7.0 (float) ERROR 23 (string) ------------ import random def random_test(max, threshold, num): count = 0 for i in range(num): r = random.randint(0, max) if r <= threshold: count += 1 return count ------------ B CC DDD EEEE ------------ As written, mystery(4) would not return anything but run forever. If we fixed it by adding the line "count += 1" as the last statement in the loop, mystery(4) would return 1+4+9+16 = 30