Question

In: Computer Science

The coding for this program to run as described on Python: Your (turtle) program must include:...

The coding for this program to run as described on Python:

Your (turtle) program must include:

  • include import turtle on a line after the comments so you can use the various Turtle-related objects and methods.
  • Create a turtle named after your favorite ice cream flavor. Make sure the name has no punctuation and consists only of letters, numbers and the underscore character.
  • Write your python program so your turtle is constantly moving and can be turned left and right using the arrow keys on the keyboard and you can speed up or slow down your turtle using the up and down arrow keys, but the turtle can never stop moving (is not allowed to have a speed of zero).
  • When you press the space bar, the turtle should move back to its starting location (0, 0) and return to its initial speed. It should also not leave a line from its original location to the center when it jumps back to start.
  • Create two additional buttons to cause your turtle to do something interesting. Explain in the comments for your program exactly what the two additional buttons do.

Solutions

Expert Solution

Here our task is to make a turtle program which move according to the user input

when no key is pressed turtle move in constant speed

when up is pressed speed increase

when down is pressed speed will reduce

when left /right pressed move left/right

when space is pressed turtle clear the window and move to origin

special functions

when c is pressed turtle draw a circle

when z is pressed turtle make a zigzag path

The complete python code for above task is given below

Please read comments for better understanding of the program

Output

I am also attaching the text version of the code in case you need to copy paste

import turtle #importing turtle library

turtle.setup(1024,768) #setting screen window
window = turtle.Screen() #initializing window
window.title("Turtle Car") #seting name for window
window.bgcolor("lightgreen")
vanila = turtle.Turtle() # turtl created with icecream flavor name

def h0(): #function for normal speed
vanila.forward(1)

def h1(): # function for fast movement
for i in range(0,50):
vanila.forward(3)

def h2(): #function for turn left
vanila.left(90)

def h3(): #function for turn right
vanila.right(90)

def h4(): #function for slow movement
for i in range(0,50):
vanila.forward(0.5)
  
  
def h5(): #function to goto (0,0) when space pressed
vanila.penup()
vanila.goto(0,0)
vanila.clear()
vanila.pendown()
  
def h6(): #function draw circle
vanila.circle(8)

def h7(): #function for zigzag movement
vanila.left(45)
vanila.forward(10)
vanila.right(90)
vanila.forward(20)
vanila.left(90)
vanila.forward(10)
vanila.right(45)
  

while(1):
h0() #normal speed will run always when no key is pressed
window.onkey(h1, "Up") #event triggered when Up pressed
window.onkey(h2, "Left") #event triggered when left pressed
window.onkey(h3, "Right") #event triggered when right pressed
window.onkey(h4, "Down") #event triggered when down pressed
window.onkey(h5, " ") #event triggered when space pressed
window.onkey(h6, "c") #event triggered when c pressed
window.onkey(h7, "z") #event triggered when z pressed
window.listen()
  

window.mainloop()


Related Solutions

Your (turtle) program in python must include: Create four Red turtles and four Blue turtles using...
Your (turtle) program in python must include: Create four Red turtles and four Blue turtles using one or more lists. • Start each of the Red turtles at a different random location on the left side of the screen within the range of the square formed by (-100, 100) and (0, -100) and each of the Blue turtles at a random location on the right side of the screen within the range of the square formed by (0, 100) and...
The code that creates this program using Python: Your program must include: You will generate a...
The code that creates this program using Python: Your program must include: You will generate a random number between 1 and 100 You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number. When their guess is too high – let them know When their guess is too low – let them know If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop...
Program must use Python 3 Your program must have a welcome message for the user. Your...
Program must use Python 3 Your program must have a welcome message for the user. Your program must have one class called CashRegister. Your program will have an instance method called addItem which takes one parameter for price. The method should also keep track of the number of items in your cart. Your program should have two getter methods. getTotal – returns totalPrice getCount – returns the itemCount of the cart Your program must create an instance of the CashRegister...
To earn full credit, program must be free of syntax, run-time, and logic errors; include program...
To earn full credit, program must be free of syntax, run-time, and logic errors; include program comments; use reasonable readable variable names and prompts. To include variables in the input prompt, you must use concatenation character (+). For example: assume you already asked for input of employee's first name and last name (they are stored into variables FirstName and LastName, then use this prompt to ask for employee's weekly hours which includes the employee's full name in the input statement....
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
What would the Python code be to create the following working program using turtle: -Make 4...
What would the Python code be to create the following working program using turtle: -Make 4 turtles that are YELLOW, and 4 turtles that are GREEN. Create these turtles using one or more lists. -Make the yellow turtles start at a different randomized location somewhere on the left side of the screen within the range of (-100,100) and (0, -100) -Make the green turtles start at a different randomized location somewhere on the right side of the screen within the...
PYTHON Find anagrams of a word using recursion. This a possible run of your program: Enter...
PYTHON Find anagrams of a word using recursion. This a possible run of your program: Enter a word or empty string to finish: poster The word poster has the following 6 anagrams: presto repost respot stoper topers tropes
Design a one-week corrective exercise program for a friend or client. Your program must include the...
Design a one-week corrective exercise program for a friend or client. Your program must include the following: Have your client fill out the Lower Extremity Functional Index and the Upper Extremity Functional Index. Summarize what the results tell you about your client (you do not need to submit the filled out forms). Conduct an Upper Body Multi-Joint Movement Assessment and a Lower Body Multi-Joint Movement Assessment on your client. Summarize your findings and how these findings influenced your program design....
Design a one-week corrective exercise program for a friend or client. Your program must include the...
Design a one-week corrective exercise program for a friend or client. Your program must include the following: Have your client fill out the Lower Extremity Functional Index and the Upper Extremity Functional Index. Summarize what the results tell you about your client (you do not need to submit the filled out forms). Conduct an Upper Body Multi-Joint Movement Assessment and a Lower Body Multi-Joint Movement Assessment on your client. Summarize your findings and how these findings influenced your program design....
Write a function that draw your initials. (Using python 3 turtle) (T, S)
Write a function that draw your initials. (Using python 3 turtle) (T, S)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT