import math
def getIntputs():
angle = eval(input('please input angle'))
vel = eval(input('please input vel'))
h0 = eval(input('please input h0'))
time = eval(input('please input time'))
return angle, vel, h0, time
#shot类的定义
class Shot:
def __init__(self, angle, vel, h0):
theta = math.radians(angle)
self.xvel = vel*math.cos(theta)
self.yvel = vel*math.sin(theta)
self.xpos = 0
self.ypos = h0
def getX(self):
return self.xpos
def getY(self):
return self.ypos
def update(self, time):
Yyvel = self.yvel - 9.8*time
self.xpos = self.xpos + Yyvel*time
self.ypos = self.ypos - Yyvel*time/2
self.yvel = Yyvel
#输出函数
def main():
angle, vel, h0, time = getIntputs()
shot = Shot(angle, vel, h0)
while shot.getY() >= 0:
shot.update(time)
print('水平距离为:{0:0.1f}meter'.format(shot.getX()))
if __name__ == '__main__':
main()
Python 之 shot 类
猜你喜欢
转载自blog.csdn.net/weixin_42143003/article/details/89235537
今日推荐
周排行