Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Why does 0.5 round to 0?

I was playing around with the code for this lesson and wanted to figure out the value with the smallest value that would result in 'a' in "Magic" when printing out user string.

One would assume that with: len(user_string = "Magic") and user_num = 0.1, ratio would equal 0.5 before rounding, thus having an index of 1 when it is rounded. However, it has an index of 0. So I was wondering why does Python (and other languages?) round 0.5 down and how would I find the smallest value of user_num to get a value of 1?

1 Answer

smart question !