Question:
Python Programming?
Jaltz
2015-02-28 05:02:13 UTC
I typed this
def max (a1, a2):
print(str(al+a2))

max(2, 3)


And this was the reply
Traceback (most recent call last):
File "C:/Users/Clive/Desktop/7pm.py", line 4, in
max(2, 3)
File "C:/Users/Clive/Desktop/7pm.py", line 2, in max
print(str(al+a2))
NameError: name 'al' is


Please help!
Three answers:
2015-02-28 05:37:57 UTC
As you keep posting questions about errors generated by simple typos try and understand what the error message is telling you...



Traceback (most recent call last):

File "7pm.py", line 4, in

max(2, 3)





It got as far as jumping into the section called max when it found a problem...





File "7pm.py", line 2, in max

print(str(al+a2))



NameError: name 'al' is not defined





in the Print instruction in max there was an error with the name al because it had not been defined and so Python had no idea what to do with it. Fix al (as husoski explained) and the code will work.
husoski
2015-02-28 05:08:43 UTC
Take a look at it in this font. You typed al instead of a1 in the print statement. Those can look very similar, particularly in typewriter-style fonts. (Trivia: Old typewriters didn't have a 1 key. Typists used a lower-case L for the digit 1.)
2015-02-28 07:55:16 UTC
If you haven't already, you shouod change the settings in your source code editor to use a font which makes it easy to tell the difference between I,l and 1 (for example Courier or Terminal).


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...