Wednesday 10/4¶
Loop Tracing Practice¶
Determine what will be printed by each of the code snippets below.
Q1¶
for n in range(3, 10, 2):
if n % 5 == 0:
print("bingo", end=" ")
else:
print(n, end=" ")
Q2¶
for c in "CS 149!":
if c.isupper():
print(c, end="")
else:
print("*", end="")
Q3¶
cars = ["Ford", "GM", "Chevy", "Ferrari"]
for i in range(len(cars) - 2):
i += 1
print(cars[i])
Q4¶
cars = ["Ford", "GM", "Chevy", "Ferrari"]
for i, c in enumerate(cars):
if c[0] == "F":
print(i, c, end=" ")
Q5¶
tallies = {3:1, 8:2, 5:4}
total1 = 0
total2 = 0
for key in tallies:
total1 += key
total2 += tallies[key]
print(total1, total2)
Quiz Instructions¶
- Log into the desktop as
student
with no password. - Log into Canvas.
- Wait until the instructor says to start before accessing Part 1.
- The quiz can be found in the "Modules" section of Canvas.
- The entire quiz has a 25 minute time limit.
- Part 1 (Conceptual):
- You may not use Thonny (or any other resources) for Part 1.
- Part 2 (Coding):
- You have unlimited submissions.
- You do NOT need to provide docstrings.
- The autograder will NOT check for PEP8 violations (though you should still use good style.)
- You must use Thonny as your editor.
- You may not access any external web pages or other resources.