Problem 1 (a) True, bool (b) 'TrueFalse', str (c) False, bool (d) 9223372036854775804L, long (e) 1.5, float (f) -8, int (g) Error, Python is unable to convert the string "2 + 5" into a float. (h) False, bool (i) 30.0, float (j) Error, the "-" operator is not defined for strings. Problem 2 (a) 15 70 15 50 45 100 45 80 75 130 75 110 (b) 64 40 24 40 24 16 8 16 8 8 (c) 24 2 3 6 (d) 1 3 5 1 5 1 Problem 3 (a) import random counter = 0 # tracks the number of rolls # numTimes tracks the number of times exactly two # of the three rolls are identical numTimes = 0 # roll three six-sided dice million times while counter < 1000000: roll1 = random.randint(1, 6) roll2 = random.randint(1, 6) roll3 = random.randint(1, 6) # First check if at least one pair of the dice rolls # have identical values; this allows either two or all three # dice rolls to have identical values. if roll1 == roll2 or roll2 == roll3 or roll1 == roll3: # Then check to make sure that not all three rolls are # identical if not (roll1 == roll2 and roll2 == roll3): numTimes = numTimes + 1 counter = counter + 1 print numTimes (b) # repeat until user types "done" while True: inputString = raw_input("Enter a positive integer: ") # Check if inputString is done and if so break out of loop if inputString == "done": break # This part of the code processes a positive integer n = int(inputString) factor = 1 # tracks potential factors of n # The string variable outputString is used to construct # the line of output with al factors of n outputString = "Factors: " # loop through all potential factors while factor <= n: if n % factor == 0: # Update the outputString outputString = outputString + str(factor) + " " factor = factor + 1 print outputString Problem 4 def relativePrimes(m, n): upperBound = min(m, n) factor = 2 while factor <= upperBound: if m % factor == 0 and n % factor == 0: return False factor = factor + 1 return True def smallerRelativePrimes(N): m = 1 count = 0 while m < N: if relativePrimes(N, m): count = count + 1 m = m + 1 return count def isPrime(n): return smallerRelativePrimes(n) == n - 1