Python Forum

Full Version: If Statements and Comparisons returns a syntax error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm self teaching python and need a bit of help . I'm trying to figure out why my code gives me a syntax error.
def max_num(num1, num2, num3):
	if num1 >= num2 and num1 >= num3:
		return num1
	elif num_2 >= num1 >= num3:
		return num2
	else:
		return num3
		
		
		
print(max_num(3, 4, 5))
I know the answer is 5 but when I try to run the code I get
 Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
    start(fakepyfile,mainpyfile)
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
    exec(open(mainpyfile).read(),  __main__.__dict__)
  File "<string>", line 11, in <module>
  File "<string>", line 4, in max_num
NameError: name 'num_2' is not defined

[Program finished] 
(Jan-02-2020, 12:59 PM)DarkAlchemyXEX Wrote: [ -> ]NameError: name 'num_2' is not defined
That is the message and it means you use the variable "num_2", but you should use "num2".
Thank you