Answered step by step
Verified Expert Solution
Question
1 Approved Answer
what is wrong with this Python code? import math def projectileMotion(v, a, h, g = 9.8): ''' According to the question We need to calculate
what is wrong with this Python code?
import math def projectileMotion(v, a, h, g = 9.8): ''' According to the question We need to calculate a list of (x, y) projectile motion data points where: x-axis is distance (m) # In while loop y-axis is height (m) # In while loop v is initial velocity of the projectile (ms-1) a is the firing angle with repsect to ground (radians) h is starting height with respect to ground (m) g is the gravity (ms-2) ''' list_xy = [] t = 0.0 while True: # now calculate the height y y = float(h) + (float(t) * float(v) * float(math.sin(a))) - float((g) * float(t * t))/2 # projectile has hit ground level if y < 0: break # calculate the distance x x = float(v) * float(math.cos(a)) * float(t) # append the (x, y) tuple to the list list_xy.append((x, y)) # time in increments of 0.1 seconds t += 0.1 return list_xy # Input here d = input('Enter angle in degrees : ') a = math.radians(d) # radians v = input('Enter the initial velocity : ') h = input('Enter the initial Height : ') # Function Call data = projectileMotion(v, a, h) # Output Calculate # Height max h_max = max(data, key = lambda q: q[1]) xh, yh = h_max print(''' Projectile Motion ... Using a firing angle of {} (degrees) and a initial velocity of {} (ms-1) the maximum height is {:0.3f} (m) at a distance of {:0.3f} (m),'''.format(d, v, yh, xh)) # Range Max ... rangeMax = max(data)[0] print("The maximum distance is {:0.3f} (m).".format(rangeMax))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started