Struggling writing this program in python - if you can point me in the right dir
ID: 3903260 • Letter: S
Question
Struggling writing this program in python - if you can point me in the right direction, would appreciate it! (I'm an older student, so perhaps brain cells are duller!) Write a program to provide information on the height of a ball thrown straight up into the air. The program should request as input the initial height, h feet, and the initial velocity, v feet per second. The height of the ball after t seconds is h+vt?16t^2 feet. The program should perform the following two calculations: Determine the maximum height of the ball. Note: The ball will reach its maximum height after v/32 seconds. Determine approximately when the ball will hit the ground. Hint: Calculate the height after every .1 second and determine when the height is no longer a positive number. A function named getInput should be used to obtain the values of h and v and that function should call a function named isValid to ensure that the input values are positive numbers. Each of the tasks (a) and (b) should be carried out by functions.
Explanation / Answer
import math
def getInput():
a = float(input("Enter height:"))
b = float(input("Enter initial velocity:"))
return a,b
def isValid(a,b):
if a < 0 or b < 0:
return False
else:
return True
h,v = getInput()
if isValid(h,v):
t1 = v/9.8
h1 = h + v*t1 + (0.5) * 9.8 * t1 * t1
t2 = math.sqrt((2*h1)/9.8)
total = t1 + t2
print("Total Time:",total)
else:
print("invalid input")