Working with numbers in Python
Integer and float arithmetic, and the operators that differ.
minutes = 947
hours = minutes // 60
remainder = minutes % 60
both = divmod(minutes, 60)
price = 19.99
tax = price * 0.0825
rounded = round(price + tax, 2)
big = 2 ** 32
ratio = 7 / 2
floored = 7 // 2
How it works
- Splits minutes into hours with floor division
//and%. divmodreturns quotient and remainder at once.- Rounds a float result to 2 places with
round. /always gives a float;//keeps integers whole.
Keywords and builtins used here
divmodround
The run, in numbers
- Lines
- 12
- Characters to type
- 201
- Tokens
- 57
- Three-star pace
- 80 tpm
At the three-star pace of 80 tokens a minute, this run takes about 43 seconds.
Step 2 of 6 in Variables & types, step 2 of 72 in Language basics.