【发布时间】:2015-09-20 02:59:00
【问题描述】:
我在 UNIX 上使用 Python。
我有这段代码,它应该采用单个输入 Z 并遍历从 A=Z 到 A=3Z 的所有 A 值,并找到每个核子的最大结合能(结合能/A)。代码如下:
Z = int(input('An atomic Number '))
B_max = 0
A_max = 0
for A in xrange(Z,3*Z+1):
B1 = calc_binding_energy(A,Z) #calculates the binding energy
#for all the values of A
B2 = float(B1/A) #finds the energy per nucleon
if B2 > B_max:
B_max = B1/A #Then if it is the max it goes back to that
#calculation for the energy per nucleon
A_max = A #Goes back to find A for the greatest energy
print(A_max)
print (B_max)
但它一直给我这个错误:
/ 不支持的操作数类型:“NoneType”和“int”当我将 Z 输入更改为浮点数时,它给了我这个错误:
float() 参数必须是字符串或数字我做错了什么?
【问题讨论】: