Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
I tried using floats but couldn't figure out how to round the answer.
Imagine you have a list of prices that aren't round numbers (whole integers). How can I modify the code from the video to print out a rounded number?
Jonathan FernandesCourses Plus Student 22,783 Points
To piggy back off of Chris, use the python method
round() to round. It follows the conventional rules of rounding. So a number less than 5 at the tenth decimal place will round up and anything below will round down. Use it like this:
my_float_number = 3.49999999 my_other_float_number = 6.78475 new_number = round(my_float_number) new_number_two = round(my_other_float_number) print(new_number) # => 3 print(new_number_two) # => 7
So yeah, the first number would round down to 3 while the second number would round up to 7. Let me know if you have any more questions.
These are all great answers, thanks. I am aware of the round() function, I just wasn't entering it correctly. Simple syntax error.