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

The python program above takes a string as input and uses that string to control

ID: 3836343 • Letter: T

Question

The python program above takes a string as input and uses that string to control what the turtle draws on the screen Currently, the program processes the following commands:

'F': moves the turtle forward

'L': turns the turtle 90 degrees to the left

'R': turns the turtle 90 degrees to the right

'^': lifts the pen

'v': lowers the pen

For example, if the user enters the string "FLFLFLFL^FFFvFLFLFLFL", the turtle would move forward and then turn left. It repeats this 4 times, drawing a square. Next, it lifts the pen and move forward 3, puts the pen back down and draw another square.

Modify this program to allow the user also to specify with the following symbols:

'B': moves the turtle backwards

'r': change the pen color to red

'g': change the pen color to green

'b': change the pen color to blue

Submit your modified program (including a comment at the top of the program with your name).

#Author: Katherine St. John #Date August 2014 #A program that uses command strings to control turtle drawing #Modified by Your Name Here! Date YouModifiedTheProgram #Date import turtle #doActionO takes a turtle and a character and has the turtle perform action indicated by the character def doActionCt,c): #move forward forward C50) elif #turn left t left 90) #turn right elif R t right (C90) el if #lift pen t.upC) elif #lower pen t down #for any other character, print an error message else: print "Error: do not know the command c) def main silas turtle Turtle O myWin turtle. Screen #The graphics window commands input "Please enter a command string "D for ch in commands doAction silas, ch) print "See graphics window for your image") #Close the window when clicked my Win.exitonclickO main O

Explanation / Answer

import turtle

def doAction(t, c):
if c == 'F':
t.forward(50)
elif c =='B':
t.backward(50)
elif c == 'L':
t.left(90)
elif c =='R':
t.right(90)
elif c == '^':
t.up()
elif c == 'v':
t.down()
elif c == 'r':
turtle.pencolor("red")
elif c == 'g':
turtle.pencolor("green")
elif c == 'b':
turtle.pencolor("blue")
else:
print("Error: do not know the command:", c)

def main():
silas = turtle.Turtle()
myWin = turtle.Screen()
commands = input("Please enter a command string: ")
for ch in commands:
doAction(silas, ch)
print("See graphics window for your image")
myWin.exitonclick()
main()

# code link: https://paste.ee/p/L2NJM

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