학교 수업/파이썬프로그래밍
부호에 따라 거북이를 움직이기(양수,0,음수)
광이11
2023. 10. 19. 21:07
import turtle
t=turtle.Turtle()
t.shape('turtle')
t.penup()
t.goto(100,100)
t.write('여기로 오면 양수')
t.goto(100,0)
t.write('여기로 오면 0')
t.goto(100,-100)
t.write('여기로 오면 음수')
t.goto(0,0) #0,0위치로 거북이를 이동시킨다.
t.pendown()
s=turtle.textinput('','숫자를 입력하시오:')
n=int(s)
if n>0:
t.goto(100,100)
elif n==0:
t.goto(100,0)
elif n<0:
t.goto(100,-100)
turtle.done()
turtle창에서 텍스트인풋 창을 듸우는 함수 : turtle.textinput('','숫자를 입력하시오:')
주의할 점 : textinput인자는 2개가 필요함. (textinput('숫자를 입력하시오')만 입력하면 오류 발생