Question

In: Computer Science

write a python program that will search through a range of launch angles (this will require...

write a python program that will search through a range of launch angles (this will require a loop statement)

the target is 500 meters away and the projectile was launched at 100m/s, the initial height of the projectile can be between 2 and 30 meters

the print statement will state the initial launch angle required to hit the target from the projectile height.

***explain each step or a rating will not be given***

Solutions

Expert Solution

CODE:

import math
#function to get the range of a projectile
#height = passing the initial height of the projectile
#v = initial velocity
#theta = angle at which the projectile is fired
def getRange(height, v, theta):
#converting theta to radians
theta = (math.pi/180.0)*theta
#Max Height = vsin(theta)^2/2g, where g = 9.8 m/s^2
g = 9.8
#finding the time of flight
#formula we get after solving the quadratic equation
#-(0.5)gt^2 + v*cos(theta)t + y0
#after solving for t we get the time of flight
time1 = -(-v*math.sin(theta) + pow(pow(v*math.sin(theta),2) + 4*height*4.9,0.5))/9.8
time2 = -(-v*math.sin(theta) - pow(pow(v*math.sin(theta),2) + 4*height*4.9,0.5))/9.8
time = 0
#using the time which is positive
if(time1<0):
time = time2
else:
time = time1
#time*velocity*cos(theta) we get the range
return v*math.cos(theta)*time
#asking the user to enter the initial height of the projectile
height = float(input('Enter the initial height of the projectile between 2m to 30m: '))
#velocity = 100m/s
v = 100
#targetRange
targetRange = 500.0
theta = 0.0
#running a loop
while(True):
#if the range of the current projectile is greater than equal to targetRange
if(getRange(height, v, theta) >= targetRange):
#we have our answer, and the angle is printed. The loop breaks
print('The projectile hits the target at angle {} degrees when fired from initial height {} meters'
.format(str(round(theta,2)), height))
break
#after each loop the angle is incremented by 0.1
theta += 0.1

___________________________________

CODE IMAGES AND OUTPUT:

_________________________________________________

Feel free to ask any questions in the comments section
Thank You!


Related Solutions

PYTHON Write a program that accepts a range of input from the user and checks whether...
PYTHON Write a program that accepts a range of input from the user and checks whether the input data is sorted or not. If the data series is already sorted your program should print “True” or should print “False” otherwise. You should not use any sort function for this program. Input: How many numbers you want to input: 3 # user input 3 Input the number: 5 Input the number: 2 Input the number: 7 Output: False
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a program that generates a random number in the range of 1 through 100, and...
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. When the number is generated by the computer, don’t display the number to the user, but only display if the number generated is odd or even. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the...
Write a program in Python that walks through a folder tree and searches for files with...
Write a program in Python that walks through a folder tree and searches for files with a certain file extension (such as .pdf or .jpg). Copy these files from whatever location they are in to a new folder. The user can enter an absolute path for the start folder, or if the user does not enter a folder, the current directory is used. Likewise, the user can enter extensions to copy but if the user does not enter an extension,...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
In python write a program that first creates a list with the integers 0 through 9...
In python write a program that first creates a list with the integers 0 through 9 and then traverses that list RECURSIVELY (no for/while loops allowed) and prints out the integers on the list. NOTE: creating the list does not have to be done recursively.
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
Calculating Delivery Cost Program in Python write a program in Python that will ask a user...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user to enter the purchase total, the number of the items that need to be delivered and delivery day. Then the system displays the cost of delivery along with the total cost. Purchase total > $150 Yes Number of the items (N) N<=5 N>=6 Delivery day Same Day Next Day Same Day Next Day Delivery charges ($) 8 N * 1.50 N * 2.50 N...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT