Lab 7: Knowledge Check
These questions check your knowledge of concepts from this lab. Use the button at the bottom to show your answers once you've attempted them.
True or false: When two
forloops are nested, their loop variables will both change to the next value from their respective sequences on every iteration of the nested loop.
If we run the following code, what would the values of the variables
cbe at the end?
a = 0 b = 0 c = 0 for _ in range(4): a += 1 for _ in range(5): b += 1 c += 1 print(a, b, c)
- a == 4, b == 5, c == 4
- a == 4, b == 5, c == 20
- a == 4, b == 9, c == 4
- a == 4, b == 20, c == 20
- a == 9, b == 20, c == 9
- other values not listed above
Which of the following problems seems like one where a nested loop would be a good choice as part of a solution? (pick one or more)
- Printing out a calendar showing the days in every month of the year.
- Asking for input until the user enters a valid value.
- Counting how many grid intersections are occupied by one player or the other in a grid-based game like Go or checkers.
- Checking for the presence of dangerous items based on separate shipping manifest lists for each train car in a train.
- Printing all of the numbers below 1000 that are divisible by 17.
Table of Contents
- Lab 7 Home
- Part 1: Memory Diagrams
- Part 2: Nested Loop Warm up
- Part 3: Nested Loops
- Knowledge Check