These questions follow Conditionals. A conditional is a fork in the road β€” the whole skill is knowing which branch runs, and why.

Questions

  1. Which of these jobs needs a conditional, and which is just a sequence of steps? (a) greet every name on a list, (b) charge less if the customer is a student, (c) print today’s date.
  2. Predict the output when temp is -5, then when it is 30.
    if temp > 25:
        print("Hot")
    elif temp > 0:
        print("Mild")
    else:
        print("Brrr")
  3. Find the bug. Python refuses to run if mark = 50: at all. What did the writer mean, and why does Python object?
  4. Predict the output when age is 16 β€” then when it is 20.
    if age >= 13:
        if age <= 19:
            print("Teen")
  5. Write a four-line snippet: ask for a password, then print Welcome if it equals sesame and No entry otherwise.
  6. Challenge. Rewrite question 4 as a single if using and β€” then suggest why real checks often keep conditions separate.

Answers

Curriculum connection

C1.4

determine the appropriate expressions and instructions to use in a programming statement, taking into account the order of operations

Link to original

C1.5

identify and explain situations in which conditional and repeating structures are required

Link to original

C2.3

write programs that include single and nested conditional statements

Link to original