19. Turtle Graphics: Hit the Target Modification Enhance the hit_the_target.py program that you saw in Program 3-9 so that, when the projectile misses the target, it displays hints to the user indicating whether the angle and/or the force value should be increased or decreased. For example, the program should display messages such as 'Try a greater angle' and 'Use less force. '

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Design and write a Python program for exercise #19: Please label your steps with comments (#) on your program
1
2
3
4
# Hit the Target Game
import turtle
# Named constants
5
SCREEN WIDTH = 600
8
6 SCREEN HEIGHT = 600
7 TARGET LLEFT_X = 100
TARGET LLEFT_Y = 250
= 250
TARGET WIDTH = 25
10 FORCE FACTOR = 30
11 PROJECTILE_SPEED = 1
NORTH = 90
12
13
SOUTH = 270
14 EAST 0
15 WEST 180
16
9
17 # Setup the window.
18 turtle.setup (SCREEN_WIDTH, SCREEN_HEIGHT)
19
20 # Draw the target.
21 turtle.hideturtle()
22 turtle.speed (0)
23 turtle.penup()
24 turtle.goto (TARGET_LLEFT_X, TARGET_LLEFT_Y)
25 turtle.pendown ()
26 turtle.setheading (EAST)
27 turtle. forward (TARGET_WIDTH)
turtle.setheading (NORTH)
28
29 turtle.forward (TARGET_WIDTH)
30 turtle.setheading (WEST)
31 turtle.forward (TARGET_WIDTH)
32 turtle.setheading (SOUTH)
33 turtle. forward (TARGET_WIDTH)
turtle.penup()
34
35
36
# Center the turtle.
# Screen width
# Screen height
#Target's lower-left X
# Target's lower-left Y
# Width of the target
#Arbitrary force factor
# Projectile's animation speed
#Angle of north direction
# Angle of south direction
# Angle of east direction
# Angle of west direction
37 turtle.goto(0, 0)
38 turtle.setheading (EAST)
turtle.showturtle()
turtle.speed (PROJECTILE SPEED)
39
40
41
42 # Get the angle and force from the user
43 angle float(input("Enter the projectile's angle: "))
44 force float(input ("Enter the launch force (1-10): "))
45
46 # Calculate the distance.
47
distance force FORCE_ FACTOR
48
49 # Set the heading.
50
51
turtle.setheading (angle)
52 # Launch the projectile.
53 turtle.pendown()
54
55
56
# Did it hit the target?
57 if (turtle.xcor () >= TARGET LLEFT_X and
58
59
60
turtle. forward (distance)
turtle.xcor () <= (TARGET_LLEFT_X+ TARGET WIDTH) and
turtle.ycor () >= TARGET_LLEFT_Y and
turtle, ycor () <= (TARGET_LLEFT_Y + TARGET_WIDTH)):
print('Target hit!')
print('You missed the target.')
61
62 else:
63
4
Transcribed Image Text:1 2 3 4 # Hit the Target Game import turtle # Named constants 5 SCREEN WIDTH = 600 8 6 SCREEN HEIGHT = 600 7 TARGET LLEFT_X = 100 TARGET LLEFT_Y = 250 = 250 TARGET WIDTH = 25 10 FORCE FACTOR = 30 11 PROJECTILE_SPEED = 1 NORTH = 90 12 13 SOUTH = 270 14 EAST 0 15 WEST 180 16 9 17 # Setup the window. 18 turtle.setup (SCREEN_WIDTH, SCREEN_HEIGHT) 19 20 # Draw the target. 21 turtle.hideturtle() 22 turtle.speed (0) 23 turtle.penup() 24 turtle.goto (TARGET_LLEFT_X, TARGET_LLEFT_Y) 25 turtle.pendown () 26 turtle.setheading (EAST) 27 turtle. forward (TARGET_WIDTH) turtle.setheading (NORTH) 28 29 turtle.forward (TARGET_WIDTH) 30 turtle.setheading (WEST) 31 turtle.forward (TARGET_WIDTH) 32 turtle.setheading (SOUTH) 33 turtle. forward (TARGET_WIDTH) turtle.penup() 34 35 36 # Center the turtle. # Screen width # Screen height #Target's lower-left X # Target's lower-left Y # Width of the target #Arbitrary force factor # Projectile's animation speed #Angle of north direction # Angle of south direction # Angle of east direction # Angle of west direction 37 turtle.goto(0, 0) 38 turtle.setheading (EAST) turtle.showturtle() turtle.speed (PROJECTILE SPEED) 39 40 41 42 # Get the angle and force from the user 43 angle float(input("Enter the projectile's angle: ")) 44 force float(input ("Enter the launch force (1-10): ")) 45 46 # Calculate the distance. 47 distance force FORCE_ FACTOR 48 49 # Set the heading. 50 51 turtle.setheading (angle) 52 # Launch the projectile. 53 turtle.pendown() 54 55 56 # Did it hit the target? 57 if (turtle.xcor () >= TARGET LLEFT_X and 58 59 60 turtle. forward (distance) turtle.xcor () <= (TARGET_LLEFT_X+ TARGET WIDTH) and turtle.ycor () >= TARGET_LLEFT_Y and turtle, ycor () <= (TARGET_LLEFT_Y + TARGET_WIDTH)): print('Target hit!') print('You missed the target.') 61 62 else: 63 4
19. Turtle Graphics: Hit the Target Modification
Enhance the hit_the_target.py program that you saw in Program 3-9 so that, when the projectile
misses the target, it displays hints to the user indicating whether the angle and/or the force value should be
increased or decreased. For example, the program should display messages such as 'Try a greater
angle' and 'Use less force.'
Transcribed Image Text:19. Turtle Graphics: Hit the Target Modification Enhance the hit_the_target.py program that you saw in Program 3-9 so that, when the projectile misses the target, it displays hints to the user indicating whether the angle and/or the force value should be increased or decreased. For example, the program should display messages such as 'Try a greater angle' and 'Use less force.'
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education