Python, Concept by Concept › Decisions
Exercises: Decisions
Core: Exercises 1–10 are the main path. More Practice: Exercises 11–16 add variety. Challenges: Exercises 17–21 are optional stretch work; no core exercise depends on them.
For every exercise, follow the specification and produce the exact output shown. Run your cell and compare every capital letter, space, and punctuation mark with the worked sample. Write the lines directly.
Exercise 1: Target Message
A practice board congratulates a player only when the given score reaches the target.
Specification: Given score, use an if statement to print Target reached! only when the score is at least 10.
Worked sample — given values:
score = 12
Expected output:
Target reached!
Real program
The real program reads a score with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 2: Even or Odd
A label needs one of two messages based on the remainder after division by 2.
Specification: Given the non-negative integer number, use if and else to print Even when its remainder after division by 2 is 0. Otherwise print Odd.
Worked sample — given values:
number = 17
Expected output:
Odd
Real program
The real program reads a number with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 3: Inclusive Range
A number checker accepts values from 0 through 10, including both endpoints.
Specification: Given x, use either x >= 0 and x <= 10 or 0 <= x <= 10. Print <x> is in range. when it is true; otherwise print <x> is out of range.
Worked sample — given values:
x = 10
Expected output:
10 is in range.
Real program
The real program reads a number to check with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 4: Weekend Label
A schedule labels Saturday and Sunday as weekend days.
Specification: Given day, use or to print Weekend when the value is "Saturday" or "Sunday". Otherwise print Weekday.
Worked sample — given values:
day = "Sunday"
Expected output:
Weekend
Real program
The real program reads a day name with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 5: Medal Ladder
A score receives the first medal threshold it reaches. Several thresholds can be true at once, so their order controls the answer.
Specification: Given score, use one top-down if/elif/elif/else ladder. Check score >= 90 for Gold first, then score >= 80 for Silver, then score >= 70 for Bronze; otherwise print Practice round.
Worked sample — given values:
score = 95
Expected output:
Gold
Notice
95 also passes the Silver and Bronze thresholds. The expected output is correct only when the highest threshold is checked first, because the first matching branch wins.
Real program
The real program reads a score with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 6: Repair the Exact-Score Check
An exact-score program stops with a SyntaxError because the condition uses assignment instead of an equality comparison.
Specification: Repair only the condition so the program prints exactly Exact score!. Put the repaired program in an empty cell in your exercises notebook.
Worked sample — broken program:
score = 90
if score = 90:
print("Exact score!")
Expected output after the repair:
Exact score!
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 7: Permission and Score
An activity requires permission first. A score requirement matters only after permission is present.
Specification: Given has_permission and score, use a nested decision. Without permission, print Permission needed. With permission and a score of at least 7, print Activity unlocked; with permission and a lower score, print Raise the score.
Worked sample — given values:
has_permission = True
score = 5
Expected output:
Raise the score
Real program
The real program reads whether permission is present and a score with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 8: Temperature Check
A temperature checker chooses one of two labels from a reading supplied as text.
Specification: Given temperature_text, convert it with int(). Print Freezing when the number is at most 32; otherwise print Above freezing.
Worked sample — given values:
temperature_text = "30"
Expected output:
Freezing
Real program
The real program reads a temperature as text with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 9: FizzBuzz for One Number
A single number needs its FizzBuzz label.
Specification: Given n, check divisibility by 15 first, then 3, then 5. Print FizzBuzz, Fizz, or Buzz for those cases; otherwise print the number itself (for example, 7 prints 7). Use an if/elif/else ladder.
Worked sample — given values:
n = 75
Expected output:
FizzBuzz
Real program
The real program reads one number with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 10: Largest of Three
Three scores need one winning value.
Specification: Given a, b, and c, compare the values with and and print Largest: <value> using an f-string. Do not use max.
Worked sample — given values:
a = 14
b = 31
c = 22
Expected output:
Largest: 31
Real program
The real program reads three numbers with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 11: More Practice: Order Three Numbers
A scoreboard needs three numbers in increasing order.
Specification: Given a, b, and c, use only comparisons, if statements, and temporary-variable swaps to arrange the values from smallest to largest. Print them on one line, separated by spaces, using an f-string. Do not use loops, lists, sorted, min, or max.
Worked sample — given values:
a = 19
b = 4
c = 11
Expected output:
4 11 19
Real program
The real program reads three numbers with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 12: More Practice: Rock-Paper-Scissors Judge
Two players choose moves, and the judge announces the result.
Specification: Given player1 and player2 as "rock", "paper", or "scissors", check a tie first and print Tie. Otherwise use a nested if: branch on player 1's move, then decide whether it beats player 2's move. Print Player 1 wins or Player 2 wins.
Worked sample — given values:
player1 = "rock"
player2 = "scissors"
Expected output:
Player 1 wins
Real program
The real program reads the two players' moves with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 13: More Practice: Quadrant Finder
A point on a coordinate map needs its location named.
Specification: Given x and y, use a nested if to distinguish the origin, an axis, and the four quadrants. Print (<x>, <y>) is the Origin for (0, 0), (<x>, <y>) is on an axis when exactly one coordinate is 0, or (<x>, <y>) is in Quadrant I, II, III, or IV using the usual signs. Use an f-string.
Worked sample — given values:
x = -3
y = 5
Expected output:
(-3, 5) is in Quadrant II
Real program
The real program reads two coordinates with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 14: More Practice: Valid Triangle
Three side lengths need a validity check before drawing.
Specification: Given positive side lengths a, b, and c, use and to require all three triangle inequalities: each pair must add to more than the third side. Print Triangle when all hold; otherwise print Not a triangle.
Worked sample — given values:
a = 2
b = 5
c = 9
Expected output:
Not a triangle
Real program
The real program reads three side lengths with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 15: More Practice: Traffic Light Art
A tiny signal picture changes with the light state.
Specification: Given state as "red", "yellow", or "green", use if/elif/else to choose three exact rows. Red prints (R) / ( ) / ( ); yellow prints ( ) / (Y) / ( ); green prints ( ) / ( ) / (G). Save the complete picture in one named triple-quoted string, then print it last. Start the first row immediately after the opening quotes and close the quotes immediately after the last row. Use no backslashes in the art itself.
Worked sample — given values:
state = "yellow"
Expected output:
( )
(Y)
( )
Real program
The real program reads a light state with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 16: More Practice: Mood Face
A score chooses a small face for the display.
Specification: Given score, use if/elif/else to choose three exact rows. For 80 or more, print ^ ^ / - / (_); for 50 through 79, print o o / - / ---; below 50, print - - / - / .... Save the complete picture in one named triple-quoted string, then print it last. Start the first row immediately after the opening quotes and close the quotes immediately after the last row. Use no backslashes or trailing spaces in the art.
Worked sample — given values:
score = 72
Expected output:
o o
-
---
Real program
The real program reads a score with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: three lines; the middle row starts with one space
Exercise 17: Triangle Logic Puzzle
A triangle label depends on how many sides are equal. The most specific case must come before the broader one.
Specification: Given side_a, side_b, and side_c, print Equilateral when all three are equal. Otherwise print Isosceles when any pair is equal. Print Scalene when no pair is equal. Use an if/elif/else ladder with equilateral first.
Worked sample — given values:
side_a = 6
side_b = 6
side_c = 6
Expected output:
Equilateral
Notice
All-equal sides also satisfy every pair-equality test, so the equilateral branch must come before the isosceles branch.
Real program
The real program reads three side lengths with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 18: Leap-Year Logic Puzzle
A calendar follows the full leap-year rule: divisible by 4, except centuries, except every 400th year.
Specification: Given year, use exactly (year % 4 == 0 and year % 100 != 0) or year % 400 == 0 as the condition. Print <year> is a leap year. when it is true; otherwise print <year> is not a leap year.
Worked sample — given values:
year = 1900
Expected output:
1900 is not a leap year.
Real program
The real program reads a year with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 19: Closed Sign
A room sign should say whether the room is closed. The saved boolean says whether the room is open.
Specification: Given is_open, use if not is_open: to print Closed. Otherwise print Open.
Worked sample — given values:
is_open = False
Expected output:
Closed
Real program
The real program reads whether a room is open with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 20: Ticket Price
A ticket booth charges by age and by weekday or weekend.
Specification: Given age and day, use a nested if inside the 13–17 age branch to choose the price. Under 13 costs $6. Ages 13–17 cost $8 on weekdays or $9 on Saturday/Sunday. Ages 18 or more cost $12 on weekdays or $14 on Saturday/Sunday. Print Ticket: $<price> using an f-string.
Worked sample — given values:
age = 15
day = "Thursday"
Expected output:
Ticket: $8
Real program
The real program reads an age and a day name with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 21: Valid Clock Time
A clock reading needs its hour and minute checked separately.
Specification: Given hour and minute, use a nested if and chained comparisons. If hour is outside 0 through 23, print Invalid hour. Otherwise check minute: outside 0 through 59 prints Invalid minute; inside that range prints Valid time.
Worked sample — given values:
hour = 23
minute = 60
Expected output:
Invalid minute
Real program
The real program reads an hour and a minute with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line