15/100 is not the same as 15.0/100?

#1

In The Tip calculation exercise, it wont accept:
tip = 15 / 100
But will accept
tip = 15.0 / 100

From the Python Shell I can see that 15 / 100 still returns 0.15, so I don't understand where the problem is.

#2

what shell? If the shell you are talking about runs python3, then yes

the problem is that in python2, a division involving two integers returns an integer, the number gets floored (round down to a integer), this division behavior was changed in python3

#4

well, i think you just answered your own question, what python2 does isn't intuitive, so its changed in python3 to make it more intuitive

#6

what python2 does has an advantage:

``````aList = [1,2,3]
print aList[len(aList)/2]``````

retrieving the middle value of a list, this will give a error in python3 (list indexes must be integers, not floats)

the problem is easily to solve in python3:

``````aList = [1,2,3]
print aList[len(aList)//2]``````

`//` is floor division. Simply fix

and with a little googling, everything is findable:

#7

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