**New course!**Every coder should learn

**Generative AI!**

+ 1

# How round numbers in Python?

I want to finish the code, but I need to know this topic. May anyone explain me "round numbers"?

3 Answers

+ 10

Чёртов Бог ,
rounding can be done in various ways with different results. so it would be a good idea to share the exercise number, or a copy of the task description.
using:
round(<number>,<number of digits>) => is is a *built-in* function and not part of the math module
https://docs.python.org/3/library/functions.html#round
floor(<number>) is a part of the math module and has to be imported
https://docs.python.org/3/library/math.html#floor
ceil(<number>) is a part of the math module and has to be imported
https://docs.python.org/3/library/math.html#ceil

+ 4

Generally, rounding a real number means making the number to nearest whole number.
1.7 to 2
1.3 to 1
Precision value greater than 0.5 then round up . Else round down or floor the value.
1.7 => 0.7 > 0.5 so nearest whole number is 2
1.3 => 0.3 < 0.5 so nearest whole number is 1.
round() function is defined in math module so you can use it like :
print( round(1.7) , round(1.3) ) #check its value by printing...

+ 1

Thank you very mach. Now I can finish code practice "Koleidoscopes" with this information)