Python 3.6: NameError: name 'A' is not defined

Python 3.6: NameError: name 'A' is not defined



I'm very new to Python (3.6). My console is giving me the following error: "NameError: name 'A' is not defined". How can I fix this error?


def NuclearBindingEnergy(A,Z):
a_V=15.67
a_S=17.23
a_C=0.75
a_A=93.2
a_P=0

if A%2==1:
a_P=0
else:
if Z%2==0:
a_P=12.0
else:
a_P=-12.0

B = (a_V)*A - ((a_S)*(A**(2/3))) - (a_C)*(Z**2/(A**(1/3))) - ((a_A)*(((A-(2*Z))**2)/A)) + ((a_P)/A**(1/2))

return B

def NuclearBindingEnergyPerNucleon(A,Z):
return NuclearBindingEnergy(A,Z)/A

print(NuclearBindingEnergy(A,Z))
print(NuclearBindingEnergy(A,Z)/A)






What are A and Z in your print statements at the bottom?

– Loocid
Sep 17 '18 at 2:16







You should define A and Z in the end two lines because you used them without defining them outside thier function.

– Azhy
Sep 17 '18 at 2:17




2 Answers
2



you have to declare A and Z variables values for example as following


A =12
Z = 5
print(NuclearBindingEnergy(A,Z))
print(NuclearBindingEnergy(A,Z)/A)



it will output


55.008666416854204
4.584055534737851






I had left out some code and spotted it - thanks for your response.

– NotEinstein
Sep 17 '18 at 2:31



When you use parameters in a function you dont need to define them because they must be defined when the function used, but when you use some function and you want to take some values inside them as a parameter so you must defined them before using in the functions parameter so in your example you just can define A and Z like :-


...
A = 20
Z = 30

print(NuclearBindingEnergy(A,Z))
print(NuclearBindingEnergy(A,Z)/A)
...



And also you can use numbers instead them like:-


...
print(NuclearBindingEnergy(70, 60))
print(NuclearBindingEnergy(80,90)/100)
...



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế