Part A: Multiple Choice Questions For each questions circle the letter of the correct answer. You may give an optional reason or optionally show your work. If you mark the correct answer, the reason will not be considered. 5 points each. Up to 4 points for reason or work.
a = 8 b = 5 b = 2 * a + 3 * b a = 2 * a + b print(b, a)a. 8 5 b. 5 8 c. 21 31 d. 31 47
n = 123 print(type(n))a. <class 'const'> b. <class 'bool'> c. <class 'int'> d. int
total = 0
for i in range(1, 5):
total += n
print(n, end="")
a. 1 3 6 10
b. 15
c. 13610
d. 1 3 6 1015
x = 2 y = 3 print(x ** y == y ** x)a. 2 3 b. 8 9 c. False d. True
import random val1 = random.randrange(0, 3) val2 = random.randrange(0, 2) print(val1 + val2)a. 2 b. 3 c. 4 d. 6
print(True or False and True)a. False b. True c. 0 d. 1
Part B: Predict Output. Construct the variable trace and predict the output. 10 points each.
a = 8 a b Output: b = 5 -----+----- b = 2 * a + 3 * b | a = 2 * a + b | print(b, a) |
a = 2 a b a + b
b = 5 -----+-----+-----
while a + b <= 50: | |
if a + b <= 15: | |
a *= 2 | |
b *= 3 | |
else: | |
a *= 3
b *= 4 Output:
print(a, b)
print(a + b)
s = "a" s t t = "b" ----------+--------- for i in range(1, 2): s = (s + t) * 2 t = t + s * 2 print(s + t) Output:
Part C: Find and Correct Errors. 15 points each.
x1 = input("Enter float value x1: ")
x1 = input("Enter float value y1: ")
x2 = input('Enter float value x2: ')
y2 = input(Enter float value y2:)
distance = (x2 - x2 ** 2 + x2 - x2 ** 2) ** 1 / 2
print("Distance between points ({x1},{y1}) and ({x2},[y2] is")
print(round(dist, 2))
--- Source code file: findmaxpop.py ----------
fin = open("michigan-cities.txt", r)
line = readline(fin)
while line ! = ""
maxpop = 10000000
maxcity = "'
fields = line_split(',')
city = fields[0].strip
state = fields[1].strip
population = fields(3).strip
if state = MI
if population > maxpop
maxpop = population
city = maxcity
line = fin.readline( )
if maxpop = 10000000:
print 'No cities in input file.\n'
else
print("Largest city in {state} is [city]."
end
--- Input file: cities.txt --------
City;State;Population
Springfield;IL;117076
Chicago;IL;2707120
Detroit;MI;706585
Des Moines;IA;207599
Indianapolis;IN;827609
Peoria;IL;115234
Ann Arbor;MI;114925