我的python 3程序有問題。當我選擇「箭頭鍵」時,我不斷收到錯誤消息。錯誤是: 該代碼是如何評論,因爲這是一個學校項目,需要代碼真正好評論。 任何提示和或建設性的批評理解:d未定義函數名稱「col」的錯誤。 Python 3,烏龜
import turtle
import time
#testing variables
x=10
y=20
#Real variables and functions
def up2():
bob.fd(45)
def left2():
bob.lt(45)
def right2():
bob.rt(45)
def stamp2():
bob.stamp()
def setRed2():
bob.color('red')
def back2():
bob.bk(45)
def quitTurtles2():
wn.bye()
def setGreen2():
bob.color('green')
def control(col, x, y, w, s, shape):
control('blue',-200,200,2,2,'turtle')
wn = turtle.Screen()
bob = turtle.Turtle()
bob.up()
bob.goto(x,y)
bob.width(w)
bob.turtlesize(s)
bob.color(col)
bob.shape(shape)
bob.down()
wn.onkey(up2, 'Up')
wn.onkey(left2, 'Left')
wn.onkey(right2, 'Right')
wn.onkey(stamp2, 'space')
wn.onkey(setRed2, 'r')
wn.onkey(back2, 'Down')
wn.onkey(setGreen2, 'g')
wn.onkey(quitTurtles2, 'Escape')
wn.listen()
wn.mainloop()
#Set up input for window name and stuff on control
def command(): #Defining A Function Called Start
try: #Trying The Statments Below
global color
global bob
name = str(input('Please Enter A Name For Your Drawing: ')) #Variable For The Name Of The Window
color = str(input('Please Enter A Colour For Your Turtle: ')) #Variable For The Color Of The Turtle
def speed2():
global speed
speed = int(input('Please Enter A Speed For Your Turtle Between 1-15: ')) #Variable For The Speed Of The Turtle
if speed >= 15 or speed <= 1:
print('Please Enter A Number between 1-15 thats 2,3,4,5,6,7,8,9,10,11,12,13 or 14, Restarting...')
print('\n')
time.sleep(2)
speed2()
speed2()
turtle.setup(500,500) #Setting Up Size Of Turtle Window
window = turtle.Screen() #Setting Up Turtle Window
window.title(name) #Giving Name To Turtle Window
window.bgcolor('black') #Setting Background Color For Turtle Window
bob = turtle.Turtle() #Giving 'Bob' Turtle Module Privileges
bob.color(color) #Changing The Color Of Turtle
bob.shape('turtle') #The Shape Of The Turtle
bob.speed(speed)
except Exception as e: #Catching Errors
print('Please Enter A correct Color, Restarting...') #Making My Program Unbrakable/Printing Words On The Screen
time.sleep(3) #Making The Program Wait 3 Seconds Before Program Continues
print ('\n') #Making A New Line
return command() #A goto command from batch programming implemented into python/Making program goto the start/returning the funtion start() after catching the error
#start()# Start The Program/Start The Function Named Start()
'''
def star(): #Creating a function named star
spins = 0 #Setting the variable 'spins' to be set at 0
while spins < 140: #Creating a condition where spins is less than 140
bob.forward(spins*10) #Times variable 'spins' by 10
bob.right(144) #Make bob go right 144 pixels
bob.pensize(10) #Making the size of the pen 10
spins += 1 #Making Spins go up each time loop play through, when spins gets to 140 function will stop
''' #Star doesn't Work atm
def square(): #automating the turtle to draw a square
bob.forward(100)
bob.right(90)
bob.forward(100)
bob.right(90)
bob.forward(100)
bob.right(90)
bob.forward(100)
#speed2()
def circle(): #automating the turtle to draw a circle
bob.circle(100,360,100)
def rectangle(): #automating the turtle to draw a rectangle
bob.forward(200)
bob.right(90)
bob.forward(100)
bob.right(90)
bob.forward(200)
bob.right(90)
bob.forward(100)
def left():
bob.left(90)
def right():
bob.right(90)
def forward():
bob.forward(100)
def commands():
print('Commands are: left, right, forward, circle, square, rectangle and commands')
while True:
command = str(input('Choose A Command: '))
if command == ('left'):
left()
if command ==('right'):
right()
if command ==('forward'):
forward()
if command ==('circle'):
circle()
if command ==('square'):
square()
if command ==('rectangle'):
rectangle()
if command ==('stop'):
break
window.bye
if command ==('Help' or command == ('commands')):
commands()
#if command == ('test'):
#while True
def project():
global choice
choice = input(str('Would you like to control your turtle with the arrowkeys or with commands? type arrowkeys or commands: '))
if choice == ('arrowkeys'):
control(col, x, y, w, s, shape)
elif choice == ('commands'):
command()
else:
print('Please Type arrowkeys or commands, restarting...')
print('\n')
time.sleep(2)
project()
project()
if choice == ('commands'):
commands()
#window.mainloop() #waits for user to close window.
大家好,歡迎StackOverflow上。我投了一個票來擱置你的問題(我也下了決心),但我想讓你知道爲什麼。這是反饋,而不是判斷。請花點時間閱讀幫助部分http://stackoverflow.com/help/mcve關於創建僅使用創建錯誤所需的代碼的示例。問題文本中明確的錯誤描述優先於截圖。如果你包含一個截圖,就像timrau在他的編輯中做的那樣。這有助於志願者更方便地解決您的問題! –
我對這個問題回答滿意嗎? –