+ 2

TypeError: 'float' object cannot be interpreted as an integer

for i in range(0, 12, 3.14): print(i)

14th Mar 2022, 4:59 AM
CodeStory
CodeStory - avatar
5 Antworten
+ 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
14th Mar 2022, 6:14 AM
HungryTradie
HungryTradie - avatar
+ 2
Explanation: The 12th decimal digit of Pi is 9: 3.141592653589793...
14th Mar 2022, 5:18 AM
CodeStory
CodeStory - avatar
+ 2
You incorrectly passed the 3rd argument as a float instead of an int
15th Mar 2022, 6:07 PM
Pythøñ Cúltîst⚔️🔥🇳🇬
Pythøñ  Cúltîst⚔️🔥🇳🇬 - avatar
+ 1
What are you trying to do?
14th Mar 2022, 5:16 AM
JOKER
JOKER - avatar