Exercises
Math
3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.
Exercise 1Passed
Print floor, ceil and round of 3.7, in that order.
Python
import math
# three lines
floor rounds down, ceil rounds up, round goes to nearest.
import math
print(math.floor(3.7))
print(math.ceil(3.7))
print(round(3.7))Exercise 2Passed
Print the mean and median of the values using the statistics module.
Python
values = [2, 4, 4, 4, 5, 5, 7, 9]
# print mean then median
statistics has both functions ready.
import statistics
values = [2, 4, 4, 4, 5, 5, 7, 9]
print(statistics.mean(values))
print(statistics.median(values))Exercise 3Passed
Adding the two decimals gives a float error. Print exactly 0.30 using Decimal.
Python
print(0.1 + 0.2)
# now print 0.30 exactly
Build each Decimal from a string, not a float.
from decimal import Decimal
print(0.1 + 0.2)
print(Decimal("0.10") + Decimal("0.20"))