【Python】动能计算


编辑日期:2021-12-21


效果


工具

  • python decimal 模块
  • IDE Pyzo

代码

from decimal import *


def kinetic_energy(mass, velocity):
    factor = Decimal(0.5)
    mass = Decimal(mass)
    velocity = Decimal(velocity)
    return factor * mass * velocity ** 2



if __name__ == "__main__":
    while True:
        mass =  input("请输入质量(kg):")
        velocity = input("请输入速度(m/s):")
        print("动能(J):", kinetic_energy(mass, velocity))
        input("")
        print("")

参考

  • 《Electronic Devices and Circuit Theory》 P.16

知识共享许可协议
本作品采用知识共享署名 4.0 国际许可协议进行许可。