+ 12
Why isn't the float being converted to an integer?
I started learning python recently and I am making a code with all the things I am learning about python so I can assimilate them better. However, in the last line of my code I tried to convert a float into an integer with the function "int()" but it doesn't work. How can I convert that float to an integer? Here is my code: https://code.sololearn.com/cd0eBeOvroLP/#py
7 Answers
+ 13
I think the function is working fine but because n is a string you are getting an error.
Change "n" to "int(n)" in that print and it should work fine.
EDIT:
No Problem 👍
+ 9
you need also to make int(n)
+ 8
Also, the last line produces a float because the result of division is always a float, even if the integers divide evenly.
E.g.
print(6 / 3) outputs 2.0
print(int(6 / 3)) outputs 2
+ 6
Thanks Hubert.
+ 6
Thanks LynTon, I'll try that
+ 2
Change 'n' to 'int(n)' to pass it as an integer. Should work
0
Change n to int