【问题标题】:Python: 'unsupported operand type(s)' errorPython:“不支持的操作数类型”错误
【发布时间】: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() 参数必须是字符串或数字

我做错了什么?

【问题讨论】:

    标签: python unix


    【解决方案1】:

    B1NoneTypecalc_binding_energy 可能没有返回您期望的数字。您需要粘贴/检查calc_binding_energy

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-12
      • 2013-10-12
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 2020-12-04
      相关资源
      最近更新 更多