0

我正在尝试在 python 中计算一些物理。例如,如果我将一个质量为 482 公斤、重 5 盎司、10 英尺的球扔到空中,我的程序会告诉我它落地多长时间、它下落的速度以及冲击力. 我试图实施影响力的公式:

import math
height = int(raw_input('Height: '))
weight = int(raw_input('Weight: '))
v = math.sqrt(2)*height*weight
mass = int(raw_input('mass: '))
K.E = 1/2(mass*v**2)
print K.E

但我收到一个错误:

Traceback (most recent call last):
  File "C:/Python27/test.py", line 6, in <module>
    K.E = 1/2(mass*v**2)
TypeError: 'int' object is not callable

另外,我不知道如何计算它会下降多长时间和下降的速度。

4

2 回答 2

2

您忘记了乘法,并且不能在变量名中使用点:

from __future__ import division

import math
height = int(raw_input('Height: '))
weight = int(raw_input('Weight: '))
v = math.sqrt(2)*height*weight
mass = int(raw_input('mass: '))
K_E = 1/2*(mass*v**2)
print K_E

请注意,我还添加了第一行,以确保1/2变为0.5而不是0.

于 2013-06-12T08:21:31.150 回答
0
def h22(ke,m,v):
    title_ar = 'الطاقة الحركية'
    title_en = 'kinetic energy'
    if ke=='':
        print("ke= ","%.2f"% (0.5*m*(v**2)),"J")
    elif m=='':
        print("m= ","%.2f"% ((2*ke)/(v**2)),"Kg")
    elif v=='':
        print("v= ","%.2f"% (sqrt((2*ke)/m)),"m/s")
    else:
        print("please write all data.")

h22('',5,8)
h22(50,'',3)
h22(47,8,'')

98个物理定律她的功能:

https://sourceforge.net/projects/hphysics/files/

于 2021-01-19T20:45:17.550 回答