Suppose we are shooting a projectile and can adjust the power/speed and angle of
ID: 3792134 • Letter: S
Question
Suppose we are shooting a projectile and can adjust the power/speed and angle of our projectile, then the distance, d, this projectile travels before impacting the ground can be calculated by:
... where p is the power and is the angle (9.8 is used as we are on Earth).
Make a program display the distance traveled for a range of inputs for this equation. First ask the user whether they want the range to be for the power or angle. Then ask for the minimum, maximum and increment size to create the range. Finally, ask for the part of the equation that is fixed (the opposite of what they chose in the first question). Display the distance traveled for all values in input range.
Example 1 (user input is underlined):
Example 2 (user input is underlined):
Example 3 (user input is underlined):
d = 2-p2 . Cos(0) , sin(0)/98 SInExplanation / Answer
# PYTHON CODE
import math
rangeParam = raw_input("Find (p)ower or (a)ngle (in degrees)?")
minimum = input("Enter minimum:")
maximum = input("Enter maximum:")
stepsize = input("Enter stepsize:")
if(rangeParam == 'p'):
angle = input("Enter angle (in degrees):")
for i in range(minimum,maximum,stepsize):
d = (2*i*i*math.cos(angle)*math.sin(angle))/9.8
print("%d:%f"%(i,d))
elif (rangeParam == 'a'):
power = input("Enter power:")
for i in range(minimum,maximum,stepsize):
d = (2*power*power*math.cos(i)*math.sin(i))/9.8
print("%d:%f"%(i,d))