# Rounding in Python

• Comments posted to this topic are about the item Rounding in Python

Tomaž Kaštrun | twitter: @tomaz_tsql | Github: https://github.com/tomaztk | blog:  https://tomaztsql.wordpress.com/

• [/edit] removed silly reply 😐

[/edit2] I think your position logic is faulty; position is 3 (not 0), position[-3] is 0 so the answer is correct but your logic states position[-2]. This might be confusion on zero- or one-based counting? Is it obvious I chose the wrong answer?

Thank you for the challenge!

• This reply was modified 8 months, 1 week ago by  fschreuder.
• This reply was modified 8 months, 1 week ago by  fschreuder.
• the answer for val2[-3] is 3, and -3 is not equal to -2

• Agreed the indexing logic isn't right.  Negative values index backwards from the end of the string (-1 being the last character, etc.)  In this case, the index of 0 and -4 are the same character (3), etc, so it would look like so:

3    0   .   0

0    1   2   3 (positive index numbers)

-4 -3 -2  -1 (negative index numbers)

I got the answer wrong, but then I looked into it because I was curious to understand it.  I'm a bit of a newbie with Python so I ran some different strings through this code in my interpreter to make sure I understood it.

Regardless, thanks for the cool exercise.

• Python newbie here.  Why is the value of val1 (and val2) 30.0 and not just 30?

• The radicand is floating point so the result will also be.  Rounding the floating point result will remain floating point.

Viewing 6 posts - 1 through 5 (of 5 total)