2017-12-13 26 views
0

저는 C++의 진정한 초보자입니다. 나는 High School Tech Apps 과정을 가르치지 만 내 교장 선생님은 내게 프로그래밍 수업을 제공했습니다. 나는 수업을 한 걸음 앞두고 ok를하고 있지만, 제대로 작동하지 않는 학생이 제출 한 프로그램을 가지고 있으며, 무엇이 잘못되었는지를 볼 수 없습니다. 이것을 파이썬 커맨드 라인에 직접 붙여 넣으면 잘 동작합니다. 유휴 상태에서 열면 작동하지 않습니다. 내가 파이썬 명령 행에 직접 붙여 넣을 경우 잘 작동,스크립트는 파이썬에서 실행되지만 파이썬 쉘에서는 실행되지 않습니다.

""" For this program to work as planned 
use the keys W,A,D, and SPACE 
W will draw a circle 
A will draw a triangle 
D will end the program 
and Space will move the turtle """ 


from turtle import * 


#this draws you a red circle 
def draw_circle(): 
    # This function draws a red circle 
    color("red") 
    width(10) 
    penup() 
    goto(-200, -200) 
    pendown() 
    circle(20) 



#this draws a green trinangle 

def draw_triangle(): 
    # This function draws a green triangle 
    color("green") 
    width(10) 
    penup() 
    goto(0, -200) 
    pendown() 
    right(180) 
    circle(15, steps =3) 

#this moves the turtle 

def move_turt(): 
    penup() 
    goto(-200, 100) 
    pendown 
    #this ends the program 

def end(): 
    bye() 


draw_circle() 
draw_triangle() 

listen() 

onkey(move_turt, "space") 
onkey(draw_circle, "w") 
onkey(draw_triangle, "a") 
onkey(end, "d") 
+0

IDLE for 3.7.0a2, Win 10을 사용하여 코드를 실행하면 프로그래밍 된대로 작동합니다. 파이썬, tkinter, IDLE, 거북이 모두 3.2에서 버그 수정이 있었고 전반적으로 수천 가지 개선이있었습니다. 개발자와 독자에게 공평하게 질문을 편집하여 이전 버전을 사용하도록 지정해야합니다 (cdlane의 대답에 대한 귀하의 의견에 따라 3.2). –

+0

@PamD, 만약 당신이 중반에 강의를 가르치고있다면, StackOverflow의 자매 사이트 중 하나 인 [cseducators.se]를 확인해 보는 것이 좋습니다. –

답변

1

: 다음은 스크립트입니다. IDLE에서 열면 작동하지 않습니다. 내가 python3에서 명령 줄에서을 실행 때 이상한

, 나는 그것으로 인해 끝에 mainloop()에 대한 호출의 부족에 코드의 바닥을 통해 폭포 반대를 참조하십시오. 그러나 파이썬의 idle3 환경에서는 mainloop()을 호출 할 필요가 없으므로 정상적으로 작동합니다.

그러나 붙여 넣기는입니다. 파이썬 인터프리터에 붙이면 프로그램이 종료되지 않으므로 작동합니다. 그것은 가치가 무엇인지에 대한 코드의 내 재

:

""" 
For this program to work as planned 
use the keys W, A, D, and SPACE 
W will draw a circle 
A will draw a triangle 
D will end the program 
and Space will move the turtle 
""" 

from turtle import * 

def draw_circle(): 
    """ This function draws a red circle """ 
    color("red") 
    width(10) 
    penup() 
    goto(-200, -200) 
    pendown() 
    circle(20) 

def draw_triangle(): 
    """ This function draws a green triangle """ 
    color("green") 
    width(10) 
    penup() 
    goto(0, -200) 
    pendown() 
    right(180) 
    circle(15, steps=3) 

def move_turt(): 
    """ move the turtle """ 
    penup() 
    goto(-200, 100) 
    pendown() 

def end(): 
    """ end the program """ 
    bye() 

onkey(move_turt, "space") 
onkey(draw_circle, "w") 
onkey(draw_triangle, "a") 
onkey(end, "d") 

listen() 
mainloop() 

당신은 파이썬 3 파이썬이 작업을하고 있습니까?

+0

파이썬 3.2를 사용하고 있습니다. 두 컴파일러에서 코드가 작동하지 않습니다. – PamD