I tried this code with the Python IDE and worked fine. However, a NameError appeared after I compiled the code using pyinstaller or executed the code in Ninja IDE. Any suggestions?
Here is my code. I'm a beginner so please don't judge!
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")
The error traces back to line 4, saying NameError - 'a' is undefined. It also indicates same error as other values within the answer list is inputted.
Thank you.
Aucun commentaire:
Enregistrer un commentaire