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

using python3 Write a Python program that lets a user search through the 'data.txt' file for...
using python3 Write a Python program that lets a user search through the 'data.txt' file for a given first name, last name, or email address, and print all the matches/results. Prompt the user for which field to search, (f) for first name, (l) for last name, or (e) for email data.txt entries are all formatted as: first_name, last_name, email, separated by TABS Your program should not read the entire file into memory, it should read line by line, and only...
Write a program including  binary-search and merge-sort in Python. it has to output the following: NeArr range(0,...
Write a program including  binary-search and merge-sort in Python. it has to output the following: NeArr range(0, 20)                                                                                                           result for searching 6 True                                                                                                  result for searching 16 False                                                                                                                              for-loop's function                                                                                                          arr range(0, 15)                                                                                                             for-loop's func result for searching 6 1                                                                                     result for searching 16 0 it has to be a simple code and please!! put the whole code together.
Write a program that will search through an array and check to see if the first...
Write a program that will search through an array and check to see if the first number in the array occurs more than once. If the first number occurs more than once, return true. Otherwise, return false. If the array is empty, return false? You will need to use a variable, loop, and if statement.
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...
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 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,...
The question: Write a program in Python that writes four random integers in range 1-100 on...
The question: Write a program in Python that writes four random integers in range 1-100 on a file named 'num.txt'. Write try-except block to handle at least two standard python error (any two errors). Hints: import random def main(): # Local variables # Open output file. # Write random numbers to the file. # Write it on to the file. # Close the file. # Call the main function. main() Here is my answer: please let me know if anything...
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,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT