-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturtleString.py
45 lines (37 loc) · 1.21 KB
/
turtleString.py
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
#Author: Katherine St. John
#Date: August 2014
#A program that uses command strings to control turtle drawing
#Name: Mohib Ahmed
#Date: Jun 13, 2023
#This program modifies this turtle program.
#Email: [email protected]
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 == 'R': #turn right
tess.right(90)
elif ch == '^': #lift pen
tess.penup()
elif ch == 'v': #lower pen
tess.pendown()
elif ch == 'B':
tess.back(50)
elif ch == 'S':
tess.stamp()
elif ch == 'l':
tess.left(45)
elif ch == 'r':
tess.right(45)
elif ch == 'p':
tess.color("purple")
else: #for any other character, print an error message
print("Error: do not know the command:", ch) #typo, was c before
print("See graphics window for your image")
myWin.exitonclick() #Close the window when clicked