Python, Concept by Concept › Numbers & Arithmetic
Exercises: Numbers & Arithmetic
Core: Exercises 1–11 are the main path. More Practice: Exercises 12–18 give extra reps. Challenges: Exercises 19–23 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, punctuation mark, and number with the worked sample. Write the lines directly.
Exercise 1: Supply Total
An art table has several packs with the same number of pencils in each pack. It needs the total number of pencils.
Specification: Given packs and pencils_per_pack, multiply them and print exactly Total pencils: <total>.
Worked sample — given values:
packs = 6
pencils_per_pack = 8
Expected output:
Total pencils: 48
Real program
The real program reads the pack count and pencils per pack with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 2: Trip Time
A trip schedule stores one duration in minutes but displays complete hours and leftover minutes.
Specification: Given the non-negative integer total_minutes, use // and % to print exactly <hours> hours <minutes> minutes.
Worked sample — given values:
total_minutes = 185
Expected output:
3 hours 5 minutes
Real program
The real program reads the trip length in minutes with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 3: Equal Share
Four teammates share a given number of meters of ribbon equally. The result should use regular division.
Specification: Given ribbon_meters and teammates, use / to print exactly Meters each: <share>. Show Python's exact float output.
Worked sample — given values:
ribbon_meters = 14
teammates = 4
Expected output:
Meters each: 3.5
Real program
The real program reads the ribbon length and number of teammates with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 4: Next-Year Age
A saved age arrived as text. It must become a number before Python can add one.
Specification: Given age_text, convert it with int(), add 1, and print exactly Next year: <age>.
Worked sample — given values:
age_text = "12"
Expected output:
Next year: 13
Real program
The real program reads the age as text with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 5: Compare Two Scores
A practice board needs direct True or False answers to two questions: whether the first score is higher, and whether it is at least as high.
Specification: Given first_score and second_score, first compare them with > and print the boolean result directly. Then compare them with >= and print that boolean result directly.
Worked sample — given values:
first_score = 18
second_score = 15
Expected output:
True
True
Real program
The real program reads the two scores with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 6: Two-Digit Report
A display separates the tens and ones places of a two-digit number.
Specification: Given number, which is an integer from 10 through 99, use // and % to print Tens: <tens> and Ones: <ones> on separate lines.
Worked sample — given values:
number = 73
Expected output:
Tens: 7
Ones: 3
Real program
The real program reads the two-digit number with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 7: Repair the Age Label
An age label stops with a TypeError because it tries to join text and an integer with +.
Specification: Repair the broken instruction by converting age with str() so it prints exactly Age: 12. Put the repaired instruction in an empty cell in your exercises notebook.
Worked sample — broken instruction:
age = 12
print("Age: " + age)
Expected output after the repair:
Age: 12
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 8: Price Calculator
A shop needs the cost of two items at the same price. The given price is saved as text, as it would be when read from input.
Specification: Given price_text, convert it with float(), multiply the number by 2, and print exactly Two cost: <total>.
Worked sample — given values:
price_text = "3.5"
Expected output:
Two cost: 7.0
Real program
The real program reads the price with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 9: Coin Change
A coin counter trades cents for the fewest quarters, then dimes, nickels, and pennies.
Specification: Given non-negative cents, use // and % to print Quarters: <count>, Dimes: <count>, Nickels: <count>, and Pennies: <count> on separate lines. Add a purpose comment explaining the coin calculation.
Worked sample — given values:
cents = 83
Expected output:
Quarters: 3
Dimes: 0
Nickels: 1
Pennies: 3
Real program
The real program reads the amount of cents with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 10: Seconds Breakdown
A timer stores a duration in seconds and needs a readable breakdown.
Specification: Given non-negative seconds, use // and % to print complete hours, remaining minutes, and remaining seconds on three labeled lines. Add a purpose comment explaining the breakdown.
Worked sample — given values:
seconds = 4000
Expected output:
Hours: 1
Minutes: 6
Seconds: 40
Real program
The real program reads the duration in seconds with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 11: Boolean Report
A scoreboard needs three direct yes-or-no checks for one score.
Specification: Given score, print the boolean results of score >= 60, score == 100, and score != 0, in that order, one per line.
Worked sample — given values:
score = 66
Expected output:
True
False
True
Real program
The real program reads the score with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 12: More Practice: Three-Digit Sum
A place-value puzzle adds the three digits of a number.
Specification: Given a three-digit integer number, separate its digits with // and %, then print their sum.
Worked sample — given values:
number = 468
Expected output:
18
Real program
The real program reads the three-digit number with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: a number
Exercise 13: More Practice: Power Pair
A square and a cube both grow from the same side length.
Specification: Given side, use ** to print Square: <value> and Cube: <value> on separate lines.
Worked sample — given values:
side = 7
Expected output:
Square: 49
Cube: 343
Real program
The real program reads the side length with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 14: More Practice: Clock Arithmetic
A twelve-hour clock wraps around after 12 rather than showing hour 0.
Specification: Given an hour from 1 through 12 and non-negative added hours, calculate (hour - 1 + added) % 12 + 1 and print <result> o'clock.
Worked sample — given values:
hour = 10
added = 5
Expected output:
3 o'clock
Real program
The real program reads the starting hour and added hours 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: Progress Bar
A ten-slot progress bar fills one slot per ten points.
Specification: Given a score from 0 through 100, calculate filled = score // 10, then build and print "#" * filled + "-" * (10 - filled).
Worked sample — given values:
score = 38
Expected output:
###-------
Real program
The real program reads the score with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 16: More Practice: Box Banner
A lab sign frames a fixed-width title.
Specification: Given title = "STAR LAB" (8 characters), build the three-line picture using "-" * 10 for the top and bottom. Save each row in a named string variable and print the exact rows.
Worked sample — given values:
title = "STAR LAB"
Expected output:
+----------+
| STAR LAB |
+----------+
Real program
The real program reads an 8-character title with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 17: More Practice: Precedence Predictions
An expression can change its value when operators group differently.
Specification: Without running the expressions first, predict the values of 6 + 4 * 2, (6 + 4) * 2, 20 // 3 % 4, 2 ** 3 * 2, and 7 + 1 > 2 * 4, in that order. Write the five predictions as comments, then check them with Python.
Worked sample — given values:
6 + 4 * 2
(6 + 4) * 2
20 // 3 % 4
2 ** 3 * 2
7 + 1 > 2 * 4
Expected output:
14
20
2
16
False
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.
Exercise 18: More Practice: Read the ValueError
A conversion crashes when decimal text is passed to int().
Specification: Read the broken int("6.25") instruction, then repair it with float() and print the resulting number. Put the repaired instruction in the starter cell.
Worked sample — given values:
print(int("6.25"))
Expected output:
6.25
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: a number
Exercise 19: Reverse Two Digits
A number puzzle reverses the two places of a given two-digit number.
Specification: Given number, which is an integer from 10 through 99, separate its tens and ones digits. Build the reversed integer with arithmetic and print exactly Reversed: <number>.
Worked sample — given values:
number = 42
Expected output:
Reversed: 24
Real program
The real program reads the two-digit number with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 20: Three-Digit Places
A place-value display separates every digit of a three-digit number.
Specification: Given number, which is an integer from 100 through 999, use arithmetic with non-negative operands to print Hundreds: <digit>, Tens: <digit>, and Ones: <digit> on separate lines.
Worked sample — given values:
number = 582
Expected output:
Hundreds: 5
Tens: 8
Ones: 2
Real program
The real program reads the three-digit number with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 21: The 1089 Trick
A three-digit number can hide a surprising constant.
Specification: Given a three-digit number whose hundreds digit is greater than its ones digit, reverse its digits as a three-digit place-value calculation. Because the hundreds digit is larger than the ones digit, the original number is the larger one — subtract the reversed number from it. Reverse the difference as three digits using // 100, // 10 % 10, and % 10; then print the sum of the difference and its reverse. A difference of 99 must be treated as 099, whose reverse is 990.
Worked sample — given values:
number = 841
Expected output:
1089
Real program
The real program reads the three-digit number with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: a number
Exercise 22: Receipt Line
A receipt adds two prices and always shows cents.
Specification: Given first_price and second_price, add them and print Total: $<amount> with exactly two digits after the decimal point using :.2f.
Worked sample — given values:
first_price = 2.4
second_price = 3.15
Expected output:
Total: $5.55
Real program
The real program reads the two prices with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 23: Framed Title
A team poster surrounds a known-width title with stars.
Specification: Given title = "GO TEAM" (7 characters) and width = 11, build a top and bottom row of "*" * width and a middle row * GO TEAM *. Save each row in a named string variable and print the exact three-line picture.
Worked sample — given values:
title = "GO TEAM"
width = 11
Expected output:
***********
* GO TEAM *
***********
Real program
The real program reads a title and a width four larger than the title's length with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines