半经验质量公式

2024-05-20 14:16:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我对编码还不熟悉,在我的计算物理课上,我得到了这个作业:class assignment

这是我为它做的代码:

A = int(input("please enter the atomic mass"))
Z = int(input("please enter the atomic number"))

def semi_empirical_mass_formula(A,Z):

    a1 = 15.8
    a2 = 18.3
    a3 = 0.714
    a4 = 23.2
    afive = [-12.0,12.0,0.0]

    if A%2 == 0 and Z%2 != 0:
        a5=afive[0]

    if A%2 and Z%2 == 0:
        a5=afive[1]

    if A%2 != 0:
        a5=afive[2]


    return (a1*A-a2*A**(2/3))-((a3*Z**2)/A**(1/3))-((a4*(A-2*Z)**2)/A)+((-12.0)/A**(1/2))

print (semi_empirical_mass_formula(A,Z))

正如你可能看到的,它不起作用,我不知道为什么它给我的答案是324.724。答案应该是~500

我对学习很感兴趣,我的教授鼓励我们向像这样的程序员社区提问。请说明如何修理它。最后一部分对我非常有益,因为我在编码方面非常缺乏经验。在

编辑:我也用“/”来表示除法,当我这样做时,它给我的答案是326.1


Tags: the答案编码inputifmassinta5