python学习--面向过程程序设计实例

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#shotput.py
from math import pi,sin,cos,radians
 
def main():   
    angle = eval(input("输入发射角度 (以度为单位):"))
    vel = eval(input("输入初始速度(以米/秒为单位):"))
    h0 = eval(input("输入初始高度(以米为单位):"))
    time = eval(input("输入时间间隔: "))
 
    xpos = 0
    ypos = h0
 
    theta = radians(angle)
    xvel = vel * cos(theta)
    yvel = vel * sin(theta)     
 
    while ypos >= 0:
        xpos = xpos + time * xvel
        yvell = yvel - time * 9.8
        ypos = ypos + time * (yvel + yvell)/2.0
        yvel = yvell
    print("\n投掷距离:{0:0.1f}米.".format(xpos))
     
if __name__ == "__main__":
    main()

 

posted @ 2017-11-16 11:15  hayden__wang  阅读(257)  评论(0编辑  收藏  举报