Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import math GRAVITY = 3 2 . 1 5 2 2 print ( Welcome to the Angry Birds aimbot! Go pig or go home!

import math
GRAVITY =32.1522
print("Welcome to the Angry Birds aimbot! Go pig or go home!")
# STEP 1
print("What is the bird's initial velocity?")
# Get the bird's initial velocity as input
init_velocity = float(input())
print("What is the bird's launch angle in degrees?")
# Get the bird's launch angle as input
launch_angle_degrees = float(input())
# Convert launch angle from degrees to radians
launch_angle_radians = math.radians(launch_angle_degrees)
print("What is the height of the slingshot in feet?")
# Get the height of the slingshot as input
slingshot_height = float(input())
"""
CALCULATE the duration of the flight in seconds
find the time it takes for the bird to hit the ground by
multiplying 2 times the initial velocity times the sin of the launch angle in radians.
Divide all of that by GRAVITY and store it into a value called time
"""
time =(2* init_velocity * math.sin(launch_angle_radians))/ GRAVITY
"""
CALCULATE the maximum horizontal distance
by multiplying the initial velocity by the cosine of the launch angle in radians by the time calculated from the previous step
Store it into a variable called distance
"""
distance = init_velocity * math.cos(launch_angle_radians)* time
# Calculate the maximum height
max_height = slingshot_height +(((init_velocity * math.sin(launch_angle_radians))**2)/(2* GRAVITY))
# PRINT the outputs of the code using these print statements (fill in the blanks), truncated to two decimal places:
print(f"Duration of flight: {time:.2f} seconds")
print(f"Bird's maximum horizontal distance: {distance:.2f} feet")
print(f"Max height of the bird: {max_height:.2f} feet")
# STEP 2
print("Enter the x-coordinate of the pig:")
# GET the pig's x-coordinate as input
x1= float(input())
print("Enter the y-coordinate of the pig:")
# GET the pig's y-coordinate as input
y1= float(input())
# CALCULATE the straight-line distance from the bird & slingshot to the pig
# Use the distance formula with the points (x-coordinate of the pig, y-coordinate of the pig) and (0, slingshot height)
straight_line_distance = math.sqrt((x1-0)**2+(y1- slingshot_height)**2)
# PRINT the results. Replace X with the calculated numbers. Truncate the output to two decimal places:
print(f"Straight-line distance to the pig:{straight_line_distance:.2f} feet")
# This is the time when the bird is directly over the pig (x1, y1)
time_pig1= x1/(init_velocity * math.cos(launch_angle_radians))
# This is the y-position of the bird at the time it is directly over pig
y_pig1= slingshot_height +(init_velocity * math.sin(launch_angle_radians)* time_pig1)-(0.5* GRAVITY * time_pig1**2)
y_pig1_dist_above = y_pig1- y1
# PRINT the results. Fill in the blanks with the calculated numbers. Truncate the output to two decimal places (0.02,12.44, etc.)
print(f"The bird will be over the pig at time {time_pig1:.2f} seconds. The bird will be {y_pig1_dist_above:.2f} feet above the pig.")
# STEP 3
print("Enter the time in seconds to calculate the bird's position:")
# GET the time as input
t = float(input())
# These are the x and y coordinates of the bird at the inputted time
x_at_inputted_time = init_velocity * math.cos(launch_angle_radians)* time
y_at_inputted_time = slingshot_height +(init_velocity * math.sin(launch_angle_radians)* time)-(0.5* GRAVITY * time**2)
# PRINT the time that was provided by the user and the coordinates of the pig at that time
# DO NOT TRUNCATE the value of the inputted time, but TRUNCATE the x and y coordinates at that time using 2 decimal places
print(f"Coordinates of bird at {t} seconds: ({x_at_inputted_time:.2f},{y_at_inputted_time:.2f})")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

More Books

Students also viewed these Databases questions