好吧,所以我已经为这个问题在我的办公桌上敲了几天,但我仍然无法得到它我一直遇到这个问题:
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 44, in <module>
File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 35, in main
File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 15, in __init__
builtins.TypeError: can't multiply sequence by non-int of type 'float'
一遍又一遍。我想我已经碰壁了,实际上我已经做了很多查看和测试,但如果有人能指出我正确的方向,我将不胜感激。
from math import pi, sin, cos, radians
def getInputs():
a = input("Enter the launch angle (in degrees): ")
v = input("Enter the initial velocity (in meters/sec): ")
h = input("Enter the initial height (in meters): ")
t = input("Enter the time interval between position calculations: ")
return a,v,h,t
class Projectile:
def __init__(self, angle, velocity, height):
self.xpos = 0.0
self.ypos = height
theta = pi *(angle)/180
self.xvel = velocity * cos(theta)
self.yvel = velocity * sin(theta)
def update(self, time):
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 main():
a, v, h, t = getInputs()
cball = Projectile(a, v, h)
zenith = cball.getY()
while cball.getY() >= 0:
cball.update(t)
if cball.getY() > zenith:
zenith = cball.getY()
print ("/n Distance traveled: {%0.1f} meters." % (cball.getY()))
print ("The heighest the cannon ball reached was %0.1f meters." % (zenith))
if __name__ == "__main__": main()