Question

In: Computer Science

In python. Projectile motion: Write a python program that will ask the user for      an...

In python.

Projectile motion: Write a python program that will ask the user for

     an initial height y0, initial velocity v, launch angle theta, and mass m.

     Create two functions, one that will calculate max height

     of the projectile, and one that will calculate the range. Ask the

    user which one he/she would like to calculate, then present them with

the answer. (use kg, m and m/s)

Solutions

Expert Solution

CODE:

import math

def getMaxHeight(y0, 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
#calculating the maxHeight
maxHeight = pow(v*math.sin(theta),2)/(2*g) + y0
#returns the maxHeight
return maxHeight
  
def getRange(y0, 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 is 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*y0*4.9,0.5))/9.8
time2 = -(-v*math.sin(theta) - pow(pow(v*math.sin(theta),2) + 4*y0*4.9,0.5))/9.8
time = 0
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 inputs
y0 = float(input('Enter initial height in metres: '))
v = float(input('Enter the initial Velocity in m/s: '))
theta = float(input('Enter launch angle in degrees: '))
#asking choice from the user
choice = int(input('Enter\n1. to calculate max height\n2. to calculate range: '))
if(choice == 1):
print('\nMax Height: '+str(round(getMaxHeight(y0,v,theta),2))+' metres')
elif(choice == 2):
print('\nRange: '+str(round(getRange(y0,v,theta),2))+' metres')
else:
print('Invalid Choice!')

______________________________________

CODE IMAGES:

__________________________________________________

OUTPUT:

_____________________________________________

Feel free to ask any questions in the comments section

Thank You!


Related Solutions

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...
Write a Python program that has a loop to continuously ask the user for a number,...
Write a Python program that has a loop to continuously ask the user for a number, terminating the loop when the number entered is -1. Inside the loop, 1.) display one asterisk(*) if the number is 1, 2.) two asterisk(**) if the number is 2 and 3.) "OTHER" if the number is any other number.
1. Write a Python program that will ask the user length and width of the right...
1. Write a Python program that will ask the user length and width of the right triangle and find the area of the right-angled triangle. The formula for finding the area of a right-angle triangle is ab/2. Also, find out the result if you calculate as (ab)/2. Is it the same? If it is same, why it is the same. If it is not the same, why it is not the same.
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
Write, save, and run a Python program Ask the user to enter a number of grams....
Write, save, and run a Python program Ask the user to enter a number of grams. Your program converts that to whole tones, then whole kilograms and whatever is left is in grams. It prints the entered grams , tones , kilograms and the remaining grams.      4 marks for i in range(0,10): print(i) 2    what is wrong in the above python code? display your explanation using print statement. mark 3    insert the following comments into your program of part...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they type DONE to quit. The program should DOUBLE each of the digits in the number and display the original entry AND the SUM of the doubled digits. Hint: Use the // and % operators to accomplish this. Print the COUNT of entries that were invalid Examples: if the user enters 93218, the sum of the doubled digits is 18+6+4+2+16 = 46. User Entry Output...
Write a Python program to: ask the user to enter two integers: int1 and int2. The...
Write a Python program to: ask the user to enter two integers: int1 and int2. The program uses the exponential operator to calculate and then print the result when int1 is raised to the int2 power. You also want to calculate the result when int1 is raised to the .5 power; however, you realize that it is not possible to take the square root of a negative number. If the value for int1 that is entered is a negative number,...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
Using Python write a program that does the following in order: 1. Ask user to enter...
Using Python write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out...
MATLAB Write a user defined function for a projectile motion. If a ball is launched from...
MATLAB Write a user defined function for a projectile motion. If a ball is launched from initial position(0,0) with a velocity v0 at angle θ, determine your horizontal and vertical position. Please plot x vs. t, y vs. t and y vs. x.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT