CODE: TU15 POINTS: 15
By default Python does something called a Bankers rounding! Which isn't what you've been taught in Maths!
The round command helps you do rounding in a scientific way. try this:
x=3.33333333
print(x)
x=round(x,2)
print(x)
Exercise 1: Can you change the rounding, so that it displays to 3 decimal places.
Exercise 2: Can you change the code, so that the variable isn't PERMANENTLY changed, but is printed to 1 decimal place?
Now try the following code:
mynumbers = [1.5,2.5,3.5,4.5,5,5,6.5,7.5]
for i in mynumbers:
print(round(i))
Are you surprised at the result? Have a look at this stepbystep version. If you are not happy with the way rounding works, then you can always write your own code to change it, but that's another challenge...