[1] (a) True (b) True (c) False (d) True (e) True [2] (a) 1.0 (b) 0.0 (c) 3 (d) -1.0 (e) 12 (f) 5.0 (g) 1.0 [3] 12 21 30 --- 20 32 --- 30 45 --- Note: output from the different values of n in the outer loop (3,4,5) is separated by ---. The values between the marks correspond to the outputs of the inner loop, where m takes on values (4,7,10), (5,8), and (6,9). [4] 10 12 12 14 14 16 16 18 18 Note: n starts at 10, increments by 2, and is printed at both beginning (pre increment) and end (post increment) of the while loop. The break statement exits the while loop when n reaches 20; the last value printed, 18, is the pre increment value of n. [5] First solution (using a break statement): ====================================================================== # Alberto Maria Segre # Modified HOTPO1 solution # Read in the number n = int(raw_input("Enter a number: ")) # We'll use count to tally the HOTPO steps. count = 0 # The HOTPO process ends normally when n reaches 1. while (n > 1): # Limit number of HOTPO steps allowed. if (count > 25): break # Proceed: handle even/odd increment. if n%2 == 0: n = n/2 else: n = (3*n + 1) count = count + 1 # At this point, n will be 1 only if you successfully # completed the HOTPO process. if (n == 1): print count else: print "HOTPO process aborted!" ====================================================================== Second solution (using a Boolean operation in the while condition): ====================================================================== # Alberto Maria Segre # Modified HOTPO1 solution # Read in the number n = int(raw_input("Enter a number: ")) # We'll use count to tally the HOTPO steps. count = 0 # The HOTPO process ends normally when n reaches 1; here, # we'll also limit the number of HOTPO steps allowed. while (n > 1) and (count <= 25): if n%2 == 0: n = n/2 else: n = (3*n + 1) count = count + 1 # At this point, n will be 1 only if you successfully # completed the HOTPO process. if (n == 1): print count else: print "HOTPO process aborted!"