Crunch some numbers. Predict the answer first, then run to check!
โก
Task 1: Power & Remainder
Easy
Print 7 to the power of 2, then print the remainder of 17 รท 5. Output:
49
2
print(7 ** 2)
print(17 % 5)
๐ฌ
Task 2: Candy Calculator
Medium
You have 4 bags with 25 candies each. Use variables bags and per_bag, multiply them, and print the total. It should be 100.
bags = 4
per_bag = 25
print(bags * per_bag)
๐ฑ
Task 3: Text Meets Numbers
Tricky
A variable count = "5" is text! Convert it to a number, add 3, then print the result followed by the word cats, like: 8 cats. (Hint: you'll need int() and str(), or an f-string.)
count = "5"
total = int(count) + 3
print(f"{total} cats")
๐ก๏ธ
Task 4: Free Play โ Temperature Converter
Creative
Convert a Celsius temperature to Fahrenheit with the formula F = C * 9/5 + 32. Change the celsius value and watch the result. Try 0, 100, and your room temperature!
๐๏ธ Extra Practice โ Drill Time!
Mathematics in code only becomes easy through repetition. Work through every drill below, from warm-up to boss level.
โ
Task 5: Divide Three Ways
Easy
Python has three kinds of division. Print 17 / 5 (normal), 17 // 5 (whole answer only) and 17 % 5 (the remainder), one per line. Notice how the first one has a decimal point and the others do not!
3.4
3
2
print(17 / 5)
print(17 // 5)
print(17 % 5)
๐ฅ
Task 6: Order of Operations
Medium
Python follows the same rules you use in math class: brackets first, then ร and รท, then + and โ. Predict each answer before running, then print 2 + 3 * 4, (2 + 3) * 4, 20 - 6 / 2 and (20 - 6) / 2.
round(x) rounds a number and round(x, 2) keeps 2 decimal places. abs(x) throws away the minus sign. Print round(2.7), round(3.14159, 2), abs(-9) and abs(9).
Python has built-in helpers. For the numbers 8, 3, 15 and 6, print the largest with max(), the smallest with min(), and their total with sum([...]) (a list goes inside sum).
There are slices = 17 pizza slices and friends = 5 hungry friends. Print how many whole slices each friend gets, and how many are left over for the dog โ two lines, like Each friend gets 3 and Leftover slices: 2.
A shop must give change = 87 cents using the fewest coins: quarters (25), dimes (10), nickels (5) and pennies (1). Print how many of each, in that order, as four lines like Quarters: 3. Hint: take the biggest coin first with //, then keep the remainder with %.
Invent a real-life calculation and code it: pocket money saved per week over a year, how many seconds you have been alive, the cost of a party for 12 friendsโฆ print the numbers with nice labeled sentences. ๐