夜光序言:
他的情绪低沉到极点,抱怨着,痛苦着:“阿衡,你看到他的眼睛了吗?言格的眼睛,他的眼睛,除了温暖和被爱,什么都没有。而我呢,小时候对着他们的电话哭过很多次,可是,为什么连一个孩子的哭泣思念都觉得碍眼……”
阿衡微笑,定定看着他,说,“让我看看,你的眼里有什么。很善良的言希,有着很多喜爱着言希的朋友的言希;很孝顺的言希,会冒险给爷爷采果子的言希;很优秀的言希连挑剔美丽的楚云都很爱很爱的言希;很骄傲的言希,强大冷静的陆流都无法强迫的言希;很温柔的言希,答应会给自己的妻子和孩子办一个画廊的言希。还有,还有眼里有着阿衡的言希……”
她说不下去,抵着他的额头,几乎哽咽。
正文:基本例子
铅球飞行轨迹计算
铅球对象属性
xpos
ypos
xvel
Yvel
构建投射体类Projectile
创建和更新对象的变量
主函数
Projectile类
引入对象,程序模块化
选手1技术强
铅球的出手角度41度
出手速度14米/秒
初始高度1.8米
仿真间隔0.3秒
铅球最远飞行距离22.2.米
选手2力量大
铅球的出手角度30度
出手速度15米/秒
始高度2米
仿真间隔0.3秒
铅球最远飞行距离23.4米
# 夜光
from math import sin, cos, radians
class Projectile:
def __init__(self, angle, velocity, 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):
#更新投射体的状态
self.xpos = self.xpos + time * self.xvel
yvell = self.yvel - 9.8 * time
self.ypos = self.ypos + time * (self.yvel + yvell) / 2.0
self.yvel = yvell
def getY(self):
#返回投射体的角度
return self.ypos
def getX(self):
#返回投射体的距离
return self.xpos
# 夜光
from Projectile import *
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: "))
return a,v,h,t
def main():
angle,vel,h0,time = getInputs()
shot = Projectile(angle,vel,h0)
while shot.getY() >=0:
shot.update(time)
print("\nDistance traveled:{0:0.1f}meters.".format(shot.getX()))
if __name__ == "__main__":
main()