This forum is now read-only. Please use our new forums! Go to forums
Tip rate error
I wrote tip = 15/100 and I get the error message
Oops, try again. It looks like tip is set to 0 instead of 0.15.
I then typed tip = 15.0/100 and it worked.
Do I have to type in .0 and if so why?
Answer 540f2b2980ff33692d0009b6
For Python version 2.x, /
performs int
eger division, if both operands are int
s. So you need to make sure at least one of them is a float
prior to performing the division, if you need float
division.
Other means of doing this are …
tip = 15 / float(100)
.. or …
tip = float(15) / 100
Answer 540f35ff52f8636916000bd7
Thanks for response -but I don’t understand?????
Why can you not simply do 15/100 - both are integers???????
Not sure of your terminology????
1 comments
Since both 15 and 100 are integers Python 2.x will round the answer down to an integer too. So 0.15 rounds down to zero. Making at least one of the numbers a non-integer ensures Python doesn’t round the answer.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
2 comments
nice
@Glenn Richard - thank you! That was a very strange thing that the tutorial doesn’t explain.