Question

import turtle player = {"name": "Player 1", "turtle" : turtle.Turtle(), "color":"blue", "radius": 10, "move_distance" : 5...

import turtle

player = {"name": "Player 1", "turtle" : turtle.Turtle(), "color":"blue", "radius": 10, "move_distance" : 5 }



#TODO: hide the player turtle

screen = player["turtle"].getscreen()


def up():

print("starting up")

t = player["turtle"] # for convenience

t.clear()

current_y = t.ycor()

# TODO: add the player's move distance to the current y

t.sety(new_y)

# TODO: use the player's radius

t.dot()

# TODO: create down, left and right functions


screen.onkey(up, "Up")

# TODO: hook up key event handlers so that arrow keys trigger appropriate function

# Can multiple keys trigger the same function? Give it a try

screen.listen()

Homework Answers

Answer #1

Ans:

'''

The required program in turtle python can be implemented in the following manner so as to satisfy the above mentioned TODO's:

'''

# PROGRAM :

import turtle

player = {"name": "Player 1", "turtle" : turtle.Turtle(), "color":"blue", "radius": 10, "move_distance" : 5 }


#TODO: hide the player turtle
player["turtle"].hideturtle() # to hide the turtle

screen = player["turtle"].getscreen()

def up():

print("starting up")

t = player["turtle"] # for convenience

t.clear()

current_y = t.ycor()

# TODO: add the player's move distance to the current y
new_y = current_y + player["move_distance"]
t.sety(new_y)

# TODO: use the player's radius

t.dot(player["radius"])

# TODO: create down, left and right functions

def down():

print("starting down")
  
def left():

print("starting left")
  
def right():

print("starting right")
  
screen.onkey(up, "Up")

# TODO: hook up key event handlers so that arrow keys trigger appropriate function

screen.onkey(down, "Down")

screen.onkey(left, "Left")

screen.onkey(right, "Right")

# Can multiple keys trigger the same function? Give it a try
'''
no! on trying multiple keys at the same time the same function doesn't
get invoked! Separate functions is needed to handle such an event

'''
screen.listen()

# OUTPUT OF A SAMPLE RUN:

# PLEASE DO LIKE AND UPVOTE IF THIS WAS HELPFUL!

# THANK YOU SO MUCH IN ADVANCE!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT