Question 1: 32/13 = int = 2 (in Python 3 this is a float, 2.46) 57%2 = int = 9 sum(range(8)) = 0+1+2+3+4+5+6+8 = int = 28 42>17 = boolean = True "do re me".split() = list = ["do", "re", "me"] "rabbit"[-1] = string = "t" "dark" + "night" = string = "darknight" "chocolate"[5:8] = string = "lat" 0.5*10 = float = 5.0 [2,3,5,7,11,13,15][2:4] = list [5,7] 2**10 = int = 1024 -- def cylinder_volume(radius,height): return math.pi*radius*radius*height (or) return math.pi*(radius**2)*height Part C.1 repeat("basket",1) means the loop iterates once so s = s + " " + s makes s "basket basket" The number of occurrences of "basket" is 2, the function returns 2 Part C.2 If the function iterates 10 times the value of s changes as follows "fun fun" -- "fun fun" + " " + "fun fun" == "fun fun fun fun" -- the number of "fun"'s doubles each time, it's 2**10 after 10 iterations and the function return 1024 Problem 2: need 5 strings, only two whose length is 3 or greater ["abcd", "abcd", "a" ,"a", "a"] need a value of x that's 7 so that 7*8=56 and all other values lower than 7 [1,2,3,4,5,7] need a string starting with "a" that's 7-letters long and all other strings that start with "a" are longer, ["america", "x", "y", "z"] easiest list: [30,0,0,0,0] Part B: def zcount(folks): tot = 0 for entry in folks: parts = entry.split(":") year = int(parts[-1]) if 1992 <= year <= 2010: tot = tot + 1 return tot (OR) temp = [1 for x in folks if int(x.split(":")[2]) in range(1992,2011)] return sum(temp) Problem 3: def nocommas(num): x = num.split(",") y = ''.join(x) return int(y) (OR) x = num.split(",") st = "" for n in x: st += n return int(st) Part B: def insert_commas(num): s = "" while num != 0: last = num % 1000 num = num/1000 s = str(last) + "," + s return s[:-1] # extra comma at end Problem 4: the loop is over a range because an index needs to be returned, the index of the first makeable sandwich. The range with len(orders) gives all valid indexes for the list orders the number of 1's in the list makes is the number of ingredients in parts that are available. If the sum of the 1's equals the length of parts then all ingredients are available and the sandwich can be made A value of -1 is returned if NO sandwich can be made. Every sandwich must be examined, that's what the loop is for. Only after the loop can a value of -1 be returned. A return within the loop might cause the function to exit/return before examining every sandwich -- def check(word): pc = word.count("pi") kc = word.count("ka") cc = word.count("chu") if 2*pc + 2*kc + 3*cc == len(word): return "YES" else: return "NO" (OR) while len(word) != 0: if word.startswith("pi") or word.startswith("ka"): word = word[2:] elif word.startswith("chu"): word = word[3:] else: return "NO" return "YES"