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.

Python Python Basics (Retired) Things That Count Exceptions

Chih-Wei Hsu
Chih-Wei Hsu
11,132 Points

when input number is .5

in the second example where the input number is .5, the resulting ratio variable should store the value 3 (from rounding 5 * .5), and the character at index 3 is 'i'. Does rounding work slightly differently in Python than the typical mathematical convention?

1 Answer

In Python, the round() function will round to the nearest integer. However, if the parameter is halfway between two integers, it rounds it to the nearest even number. So round(2.5) would output 2, while round(3.5) would output 4.