![]() |
If Statements and Comparisons returns a syntax error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: If Statements and Comparisons returns a syntax error (/thread-23490.html) |
If Statements and Comparisons returns a syntax error - DarkAlchemyXEX - Jan-02-2020 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] RE: If Statements and Comparisons returns a syntax error - ibreeden - Jan-02-2020 (Jan-02-2020, 12:59 PM)DarkAlchemyXEX Wrote: NameError: name 'num_2' is not definedThat is the message and it means you use the variable "num_2", but you should use "num2". RE: If Statements and Comparisons returns a syntax error - DarkAlchemyXEX - Jan-02-2020 Thank you |