Question: Can you tell me whats wrong with my code it keeps saying File / Users / adriyanakinard / github - classroom / CPSC 1

Can you tell me whats wrong with my code it keeps saying File "/Users/adriyanakinard/github-classroom/CPSC1050S24/lab-02-angry-birds-AdriyanaKinard/lab02.py", line 38, in
max_height = slingshot_height +(((init_velocity * math.sin(launch_angle_radians))**2)/(2* GRAVITY))
^^^^^^^^^^^^^^^^^^^^
NameError: name 'launch_angle_radians' is not define # Don't forget the header - Richard Khouri :)
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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!