January 18, 2023 at 12:00 am
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/
January 18, 2023 at 7:46 am
[/edit] removed silly reply 😐
[/edit2] I think your position logic is faulty; position[0] 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!
January 18, 2023 at 2:33 pm
the answer for val2[-3] is 3, and -3 is not equal to -2
January 18, 2023 at 2:43 pm
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.
January 19, 2023 at 4:04 pm
Python newbie here. Why is the value of val1 (and val2) 30.0 and not just 30?
January 19, 2023 at 7:37 pm
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)
You must be logged in to reply to this topic. Login to reply