-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturtleStringProg30.py
More file actions
42 lines (37 loc) · 1.32 KB
/
turtleStringProg30.py
File metadata and controls
42 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#Modified by: Daniel Tchonkadze
#Email: danieltchonkadze@gmail.com
#A program that uses command strings to control turtle drawing
import turtle
tess = turtle.Turtle()
myWin = turtle.Screen() #The graphics window
commands = input("Please enter a command string: ")
for ch in commands:
#perform action indicated by the character
if ch == 'F': #move forward
tess.forward(50)
elif ch == 'L': #turn left
tess.left(90)
elif ch == 'l': #turn left 45
tess.left(45)
elif ch == 'R': #turn right
tess.right(90)
elif ch == 'r': #turn right 45
tess.right(45)
elif ch == '^': #lift pen
tess.penup()
elif ch == 'v': #lower pen
tess.pendown()
elif ch == 'B': #go backwards
tess.backward(50)
elif ch == 'S':
tess.stamp()
elif ch == 'g': #turn green
tess.color("green")
elif ch == 'b': #turn blue
tess.color("blue")
elif ch == 'p': #turn purple
tess.color("purple")
else: #for any other character, print an error message
print("Error: do not know the command:", c)
print("See graphics window for your image")
myWin.exitonclick() #Close the window when clicked