使用下面的代码我收到错误:
Traceback (most recent call last):
File "E:\turtleTest2.py", line 4, in <module>
x = input(int("Choose a number for the spirograph to use "))
ValueError: invalid literal for int() with base 10: 'Choose a number for the spirograph to use '
#TURTLES!!!2
import turtle
x = input(int("Choose a number for the spirograph to use "))
def drawASquare(whichTurtle):
for loopCounter in range(4):
whichTurtle.forward(200)
whichTurtle.right(x)
window = turtle.Screen()
timmy = turtle.Turtle()
timmy.speed(0)
colorCounter = 1
while True:
drawASquare(timmy)
timmy.left(2)
if colorCounter == 1:
timmy.color('blue')
elif colorCounter == 2:
timmy.color('red')
elif colorCounter == 3:
timmy.color('yellow')
elif colorCounter == 4:
timmy.color('green')
colorCounter = 0
colorCounter += 1
我正在为学校的一个项目做这个,以了解有关Python编程的更多信息。任何帮助将不胜感激,谢谢!
答案 0 :(得分:4)
你已经向后调用了内置插件。它应该是这样的:
x = int(input("Choose a number for the spirograph to use "))
上面的代码获取输入,然后将其转换为整数。您的原始代码试图将其转换为整数:
"Choose a number for the spirograph to use "
永远无法运作。