Lab 5: 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.
-
A while loop will exit immediately if the continuation condition becomes false, even if it's in the middle of the loop body.
True False -
Which of the following statements are true about while loops?
- While loops continue forever until the user asks them to stop.
- It's possible for a while loop to iterate 0 times, effectively skipping the loop body.
- Within a while loop, you may not create a conditional or another loop.
- The continuation condition of a while loop is only evaluated once.
- By reading the code for a while loop, the programmer can always figure out how many times the loop will iterate.
-
Which of the following is an index loop over the indices in the word 'hello'?
-
i = 0 while i
-
i = 0 while i
-
while i in range(len('hello')): letter = 'hello'[i] ...
-
while letter in 'hello': ...
-
-
For which of the following tasks would a loop be an appropriate tool to use as part of an elegant solution? (pick one or more)
- Check that someone's name, date-of-birth, and account number match against a database.
- Print out the first 20 Fibbonacci numbers.
- Draw lots of little spikes on the tail of a monster.
- Estimate how long someone will have to wait on the phone based on the number of callers already waiting.
- Decide which restaurant is best to recommend based on a user's preferences.