我在Python IDE中尝试了这段代码并且工作正常。但是,在使用pyinstaller编译代码或在Ninja IDE中执行代码后出现了NameError。有什么建议吗?
这是我的代码。我是初学者,所以请不要判断!
from math import sqrt
while True:
numbers = int(input('Input the total amount of numbers with uncertainties you wish to use: '))
answer = str(input('Type A/a for addition of uncertainties or M/m/D/d for division/multiplication of uncertainties:'))
count = 1
mylist = []
secondlist = []
listsqrnum = []
listsqrun = []
finallist= []
listnum = []
listuncertainty = []
listofanswer1 = ["A","a"]
listofanswer2 = ["d","D","M","m"]
if answer in listofanswer1:
while count <= numbers:
num = float(input('Input uncertainty ' + str(count) + ': '))
count += 1
mylist.append(num)
for i in mylist:
secondlist.append(i ** 2)
x = sqrt(sum(secondlist))
print (x)
elif answer in listofanswer2:
result = float(input("Input resulting value: "))
while count <= numbers:
number = float(input("Input number " + str(count) + ": "))
uncertainty = float(input("Input uncertainty number " +str(count)+ ": "))
listnum.append(number)
listuncertainty.append(uncertainty)
count +=1
for i in listnum:
listsqrnum.append(i ** 2)
for i in listuncertainty:
listsqrun.append(i**2)
for i in range(0,len(listsqrnum)):
finallist.append(listsqrun[i]/listsqrnum[i])
sumofsquare = sum(finallist)
squareroot = sqrt(sumofsquare)
final = result * squareroot
print (final)
else:
print("You have not typed anything or you entered a float")
错误追溯到第4行,说NameError - &#39; a&#39;未定义。 它还表示与输入答案列表中的其他值相同的错误。
谢谢。