Python by Projects › Checkpoint 1 — First Steps
Questions: Checkpoint 1 — First Steps
This is your chance to show what you've got from Story Machine and Number Detective. There are no trick questions. Read each one carefully, try your best, and leave a note when you want to explain your thinking.
Question 1
A programmer runs this code and gets an error message. The broken code is shown as text, so do not try to run it.
clues_found = 4
print("Clues found: " + clues_found)
The last line of the traceback says:
TypeError: can only concatenate str (not "int") to str
Read that message from the bottom up. What two types is Python being asked to join? Then write a corrected version that uses str(...) to convert clues_found, builds clue_message with working + string concatenation, and prints clue_message.
How this is checked: Checked by tests that run your code.
Question 2
Predict exactly what this program prints. Work out the arithmetic before you run anything.
stars = 8
bonus = 3
total = stars + bonus * 2
print(f"Detective score: {total}")
Write the complete output, including the words and number.
How this is checked: Checked by comparing your prediction with what the program really prints.
Answer format: one line
Question 3
Write one line of Python that asks How many clues? , converts the typed answer to an integer, and stores it in a variable named clue_count.
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Question 4
Trace this if/elif/else chain. Which one message prints, and why are the other two skipped?
secret = 20
guess = 27
if guess < secret:
print("Too low")
elif guess > secret:
print("Too high")
else:
print("Correct")
How this is checked: Checked by comparing your prediction with what the program really prints.
Answer format: one line
Question 5
Complete only the condition after while. The loop should keep asking while the guess is different from the hard-coded secret. Do not add a counter.
secret = 7
guess = int(input("Guess: "))
while __________:
guess = int(input("Guess again: "))
print("You found it!")
Write the missing condition, not the whole program.
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Question 6
Two programmers store the same thing. Which name makes the program easier to understand: x or player_guess? Explain your choice in one sentence.
Then write a useful comment for this line. Your comment should explain why the value matters instead of repeating the code.
secret = 42
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Question 7
Build a one-guess detective. Keep the hard-coded secret value in the starter. Ask for one integer guess, then use if, elif, and else to print exactly one clue: Too low!, Too high!, or Case closed!.
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.