Week 3 Quiz
The user types 25, and the program stores the typed value as a string. What does the last line print?
typed = "25" print(typed * 2)Select one.
- 50
- 25
- 2525
- TypeError
The program converts the typed value before adding. What does the last line print?
typed = "25" age = int(typed) print(age + 1)Select one.
- 26
- 251
- 2525
- TypeError
The reading log prints its status line. What does the last line print?
pages_read = 45 print(f"{pages_read} pages read so far")Select one.
- {pages_read} pages read so far
- 45 pages read so far
- pages_read pages read so far
- TypeError
Count from 0, and remember a slice drops its stop. What does the last line print?
book = "the river book" print(book[4:9])Select one.
- river
- iver
- rive
- river
What does the last line print?
book = "the river book" print(book[-1])Select one.
- t
- k
- o
- IndexError
Predict, then check: what does this one-line program print?
print("PYTHON"[1:4])Select one.
- YTH
- PYT
- YTHO
- PYTH
The title has 14 characters. When this program runs, what happens?
book = "the river book" print(book[14])Select one.
- It prints k
- It prints an empty line
- It prints the river book
- IndexError, with nothing printed
Which of these lines print without raising an error? Select every line that does.
book = "the river book" pages_read = 45Select every option that applies.
- print(book[13])
- print(book[4:99])
- print(book[14])
- print(pages_read + " pages read so far")
- print(book[len(book)])
A chatbot tells you that
print("PYTHON"[1:4])displays YTHO, because the slice runs from index 1 to index 4. What is the best next step?Select one.
- Accept YTHO, since the chatbot named both indexes
- Ask the chatbot again until it gives one reply twice
- Switch to a chatbot that sounds more confident
- Run the line in a Python runner and compare its output with the claim
This program prints Now reading: the river book and then stops at line 3. Because a line printed before the error, the program was running when it stopped, so this is a runtime error, and the last line of its error message names TypeError.
book = "the river book" print(f"Now reading: {book}") print(45 + " pages read so far")True or false.
- True
- False
Built with The Course Maker · samples.thecoursemaker.com