+ 2
TypeError: 'float' object cannot be interpreted as an integer
for i in range(0, 12, 3.14): print(i)
5 Réponses
+ 5
I may not be 100% accurate, but I think:
Python "in range" takes 3 arguments, start, stop (not inclusive of the stop value), and step. You typed it like you wanted it to start at 0, step +3.14 until you exceed 12. First return would be 0, next is 3.14, next is 6.28, next 9.44, then it exceeds 12 so that's the end.
Main problem is: Your statement won't work because 3.14 is a float and range only steps in integers.
https://stackoverflow.com/questions/477486/how-to-use-a-decimal-range-step-value
+ 2
Explanation:
The 12th decimal digit of Pi is 9: 3.141592653589793...
+ 2
You incorrectly passed the 3rd argument as a float instead of an int
+ 1
What are you trying to do?