Level 1 exam — harder

Exam — fresh questions

1.1 · Recall

1. What does the input() function always return?

input() ALWAYS returns text: int() or float() before any computation.
1.1 · Application

2. Nabil writes print("I am " + age) with age = 30. What happens?

Strong typing: convert (str(age)) or use an f-string f"I am {age} years old".
1.2 · Recall

3. In Python, what is indentation for?

4 spaces per level; mixing spaces/tabs raises IndentationError.
1.2 · Application

4. Nabil classifies: if age < 12, elif age < 18, elif age < 65, else. Where does a 26-year-old respondent fall?

Evaluation in order, stopping at the first true one: specific→general order guarantees uniqueness.
1.3 · Application

5. Nabil walks through a list of names. Recommended writing?

Plain for is readable and index-error free; enumerate() if the number is used.
1.3 · Recall

6. When should you prefer while over for?

for = what you walk through; while = as long as, with guaranteed exit.
1.4 · Application

7. Nabil's function displays with print but forgets return. What is the call worth?

Only return passes on a storable, computable result.
1.4 · Application

8. Nabil writes def add(x, items=[]) and calls it twice. What happens?

The mutable default is created only once: write def add(x, items=None).
1.2 · Arbitration

9. Two tests overlap and a case falls into the wrong group. Decision?

Order guarantees uniqueness; else catches oversights.
1.3 · Arbitration

10. Nabil's retry while runs forever. Decision?

One variable of the condition must change each round; Ctrl+C unblocks.
1.5 · Application

11. In Nabil's address book, where should the menu loop be?

One verb = one function; main() holds only the menu loop that calls.
1.5 · Arbitration

12. Nabil knows each concept in isolation but freezes facing the blank page. Decision?

Decomposition beats the blank page; one finished project alone proves the foundation.
What's next?
Back to the guideGuide contents