So for this program im trying to print out the max height the projectile reaches and when i run the str on the object it dosent change the value to the string and just gives a garbage result. the program als o prints some other vaulues but my problem is with the max height portion
from math import sin, cos, radians
class Projectile:
"""Simulates the flight of simple projectiles near the earth's
surface, ignoring wind resistance. Tracking is done in two
dimensions, height (y) and distance (x)."""
def __init__(self, angle, velocity, height):
"""Create a projectile with given launch angle, initial velocity and height."""
self.xpos = 0.0
self.ypos = height
theta = radians(angle)
self.xvel = velocity * cos(theta)
self.yvel = velocity * sin(theta)
def update(self, time):
"""Update the state of this projectile to move it time seconds farther into its flight"""
self.xpos = self.xpos + time * self.xvel
yvel1 = self.yvel - 9.8 * time
self.ypos = self.ypos + time * (self.yvel + yvel1) / 2.0
self.yvel = yvel1
def getY(self):
"Returns the y position (height) of this projectile."
return self.ypos
def getX(self):
"Returns the x position (distance) of this projectile."
return self.xpos
def getInputs():
a = eval(input("Enter the launch angle (in degrees): "))
v = eval(input("Enter the initial velocity (in meters/sec): "))
h = eval(input("Enter the initial height (in meters): "))
t = eval(input("Enter the time interval between position calculations: "))
return a,v,h,t
def maxHeight():
time=self.yvel/9.8
self.maxheight=self.ypos+time*(self.yvel/2.0)
return self.maxheight
def __str__():
return str(maxHeight)
def main():
angle, vel, h0, time = getInputs()
cball = Projectile(angle, vel, h0)
while cball.getY() >= 0:
cball.update(time)
print("\nDistance traveled: {0:0.1f} meters.".format(cball.getX()))
print("\nMaximun height:" + str(maxHeight) + " meters")
if __name__ == "__main__":
main()
this returns
Distance traveled: 232.5 meters.
Maximun height:<function maxHeight at 0x05A2E9C0> meters
input
Enter the launch angle (in degrees): 60
Enter the initial velocity (in meters/sec): 50
Enter the initial height (in meters): 20
Enter the time interval between position calculations: 0.1