Why does it matter if I do 15 / 100 instead of 15.0 / 100?


#1



https://www.codecademy.com/courses/python-beginner-GB6hM/0/3?curriculum_id=4f89dab3d788890003000096


I'm doing the Tip Calculator thing. Why does it matter if you do 15.0 / 100 verses 15 / 100 to get 15%?


meal = 44.50
tax = 0.0675
# Why does it matter if I do 15 / 100 instead of 15.0 / 100
tip = 15.0 / 100


#2

because if the division involves two integers, python will floor the number (round down), so 15/100 would be zero.


#3

So 0 counts as the third integer?
Thanks!


#4

sorry, what? I guess no

15 is a integer, 15.0 is a float

if the division involves two integers (15 and 100) the result will be round down to the nearest integer value (0)

if the division involves a float and a integer (15.0 and 100) the result will not be round down


#5

Oh gosh, sorry. I was thinking that integer meant digit for some reason. That makes a lot more sense. Thanks!


#6

nope? In the first few exercises you would have been introduced to integer (data type)

if i wanted to say digit, i would say digit :wink: Good it makes sense now :slight_smile:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.