Skip to content

Numbers and math

Numbers are different from text: they’re written without quotes. When you leave the quotes off, Python actually does the math:

Inputs (for input())

One value per line — read in order by input().

Output
 

See that? 5 + 3 was calculated and came out as 8, while "5 + 3" was printed as plain text. Quotes = text, no quotes = number.

SignOperationExampleResult
+addition7 + 29
-subtraction7 - 25
*multiplication7 * 214
/division7 / 23.5
//whole division7 // 23
%remainder7 % 21
**power7 ** 249

Here’s how to remember the // and % pair: share 7 candies among 2 kids — each one gets 7 // 2 = 3 candies, and 7 % 2 = 1 candy is left over. 🍬

How many seconds are there in a day? Easy:

Inputs (for input())

One value per line — read in order by input().

Output
 

Look at the second line: 2 to the power of 100 — an ordinary calculator can’t handle it, but Python doesn’t even blink. 😎

Mission

How many hours in a year?

+10 XP

Have Python calculate how many hours are in a year. (Don’t type the answer yourself — use multiplication!)

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Sharing apples

+15 XP

17 apples, 5 kids. Use // and % to work out: how many apples does each kid get, and how many are left over?

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

The power of powers

+10 XP

There’s a famous number in the world of computers: 2 to the power of 10. Have Python calculate it and see the result.

Inputs (for input())

One value per line — read in order by input().

Output
 

Next lesson: variables — boxes for storing information. One of the most important ideas in all of programming. Continue →