Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I can get this turtleControl python script to run but it doesnt do anything. No

ID: 3771718 • Letter: I

Question

I can get this turtleControl python script to run but it doesnt do anything. No error or anything. Can you show me what i did worn? Heres the instructions and the script. Thank you for any help!

Type in the script called TurtleControl.py on page 4.   It allows the user to interactively control a turtle by typing commands.

    Q for quit          Example: Q

    L for left          Example: L 90

    R for right         Example: R 45

    F for forward       Example: F 200

Test TurtleControl.py by entering commands from the above list. Screenshot the resulting drawing.

The code for TurtleControl.py is on page 2.

Part B2: 25%

Modify TurtleControl.py to support additional commands. Some of them take parameters. Some don’t.

          U for up

          D for down

          H for heading

B for back

C for circle

S for speed

Test all your commands. Sreenshot a trial run.

Stretch goal: Implement commands to change the turtle color and shape.

Part B3: 25%

Save TurtleControl.py to the filename TurtleFile.py.   Then:

Comment out the line that asks the user input.

Modify it to read from a file called turtlecommands.txt, with one turtle command per line. Have the program execute each command as though a user had typed it in.

''' TurtleControl.py

Ask the user for commands for a turtle. The turtle
excutes that command. Our supported commands are:
Q for quit Example Q
L for Left Example L 90
R for right Example R 45
F for forward Example F 200
U for UP
D for Down
H for Heading
B for Back
C for Circle
S for Speed
'''

from turtle import *

def parseCommand (tinput):
param = 0
cmd = ""

if tinput:
tinput = tinput.upper() # make our data uppercase
tinput = tinput.strip() # remove trailing whitespace

cmdList = tinput.split() # split the tinput string into list
cmd = tinpit[0] # cmd = first item in List


if len (cmdList) > 1: # do we have a second value?
param = float( cmdlist[1]) # store it in 'param'

return cmd,param


def main():
leo = Turtle()
leo.shape ("turtle")
while True:
tinput = textinput("TurtleControl;", "Command for Leonardo?")
cmd,param = parseCommand(tinput)
# handle our cmd with a big list of if elif statements.


if cmd=="Q": # exit the while loop
break
elif cmd == "L": # turn left
leo.left(param)
elif cmd == "R": # turn right
leo.right(param)
elif cmd== "F": # go forward
leo.forward (param)
elif cmd== "C": # go up
leo.circle (param)
  


if __name__=="__main__":
main()
print("Done!")

Explanation / Answer

There were some typos here and there. Otherwise it is working fine. I corrected it

''' TurtleControl.py
Ask the user for commands for a turtle. The turtle
excutes that command. Our supported commands are:
Q for quit Example Q
L for Left Example L 90
R for right Example R 45
F for forward Example F 200
U for UP
D for Down
H for Heading
B for Back
C for Circle
S for Speed
'''
from turtle import *
def parseCommand (tinput):
param = 0
cmd = ""
if tinput:
tinput = tinput.upper() # make our data uppercase
tinput = tinput.strip() # remove trailing whitespace
cmdList = tinput.split() # split the tinput string into list
cmd = tinput[0] # cmd = first item in List

if len (cmdList) > 1: # do we have a second value?
param = float( cmdList[1]) # store it in 'param'
return cmd,param

def main():
leo = Turtle()
leo.shape ("turtle")
while True:
tinput = raw_input("TurtleControl; Command for Leonardo?")
cmd,param = parseCommand(tinput)
# handle our cmd with a big list of if elif statements.

if cmd == "Q": # exit the while loop
break
elif cmd == "L": # turn left
leo.left(param)
elif cmd == "R": # turn right
leo.right(param)
elif cmd== "F": # go forward
leo.forward (param)
elif cmd== "C": # go up
leo.circle (param)
  

if __name__=="__main__":
main()
print("Done!")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote