Why do I have to add the float(variable) code to have python do what it's supposed to do by default?


#1


https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096

Before I created the division variable and used it to divide into a floating point value, my code would for some reason integer divide when I used \ 2 at the end of the parentheses in the if statement. Why is that?


Did using \ switch the default division to integer and not float for the remainder of the code?


`python

division=2
if len(x)%2==0:
return (x[(len(x)//2)-1]+x[(len(x)//2)])/float(division)


#2

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