Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new Python code file and save it with the name a04_raging_rabbits.py. You will need to add these two lines at the top of

image text in transcribedimage text in transcribed

Create a new Python code file and save it with the name a04_raging_rabbits.py. You will need to add these two lines at the top of your file to access some libraries for this program: from a04_artillery-games import calculate_projectile_distance from a04_artillery_games import calculate_launch_angle import random Write the function raging_rabbits to implement an input-process-output program for this interactive game. See sample interactions below. The basic algorithm of the game is as follows: a. Prompt the user to enter their cannon's launch velocity (e.g., 120 m/s). b. Given this launch velocity, calculate the minimum and maximum distance that the projectile could travel. The cannon could be aimed between 10 and 45 degrees, which will give us the minimum and maximum distance to the target. Print out this range. c. Pick a random distance to the target that is within this range (hint: use random.randint). Save this distance in a variable, and display it to the game's player (i.e., so they know the goal distance). d. Prompt the user to enter the launch angle in degrees (basically, this is guessing game). e. Finally, calculate the actual distance the projectile will travel at this angle and initial velocity, and calculate the "error", i.e., how far off target was the shot. Print this out as well. A positive error means the projectile fell short of the target, and a negative error means the projectile fell long of the target. Sample Program Run 1 Welcome to Raging Rabbits! Enter your cannon's initial launch velocity (in m/s): 120 At an initial launch velocity of 120 meters/second, your cannon can hit a target between 502.56 and 1469.39 meters. Your target is located at 1156 meters. Enter your launch angle (in degrees): 40 Your projectile traveled 1447.06 meters. Your shot was -291.06 meters from the target. def calculate_projectile_distance (launch_angle, initial_velocity): ""'"calculate the distance of projectile using launch angle theta and initial velocity (m/s)" #convert the angle from degrees to radians theta = math.radians (launch_angle) #find sin of theta in radians sin = math.sin(2 * theta), #calculate distance D = (initial_velocity**2 / 9.8) * sin return D calculate_launch_angle(distance, initial_velocity): "calculate the launch angle from distance and initial velocity."" V W #find arcsin of (9.8/v**2) * D x= 9.8 / (initial velocity ** 2) U U radians = 0.5 * math.asin(x * distance) U W #convert radians to degrees degrees = math.degrees (radians) W return degrees

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+ (c) From (18.10) deduce T(4) = VIT.

Answered: 1 week ago