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....
PYTHON: Turtle Command Interpreter You will write a program that reads a sequence of codes, converts...
PYTHON: Turtle Command Interpreter You will write a program that reads a sequence of codes, converts them into Turtle commands, and then executes them. The codes are in a Python list, passed as an argument to your function. turtleRunner(t, x) t is a Turtle x is a list of Turtle commands Code List (f, d)    Move forward by d pixels u Lift pen up d Put pen down (l, d) Turn left by d degrees (r, d) Turn right...
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...
How to make a python program that imports only turtle and math library where I can...
How to make a python program that imports only turtle and math library where I can click once on the screen to set the center of the square, move the mouse to define the edge-length of the square; click a second time to draw the square with the defined edge-length and center point?
*** Using Python *** Your program must prompt the user for their city or zip code...
*** Using Python *** Your program must prompt the user for their city or zip code and request weather forecast data from openweathermap.org. Your program must display the weather information in an READABLE format to the user. Requirements: Create a Python Application which asks the user for their zip code or city. Use the zip code or city name in order to obtain weather forecast data from: http://openweathermap.org/ Display the weather forecast in a readable format to the user. Use...
The coding must be formatted in Python. Write a function matrix_power(A, n) that computes the power...
The coding must be formatted in Python. Write a function matrix_power(A, n) that computes the power An using Boolean arithmetic and returns the result. You may assume that A is a 2D list containing only 0s and 1s, A is square (same number of rows and columns), and n is an integer ≥ 1. You should call your previously written matrix multiply boolean function. Example: Let R = [ [0, 0, 0, 1], [0, 1, 1, 0], [0, 0, 0,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT