Python Forum
If Statements and Comparisons returns a syntax error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If Statements and Comparisons returns a syntax error
#1
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.
1
2
3
4
5
6
7
8
9
10
11
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
1
2
3
4
5
6
7
8
9
10
 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]
Reply
#2
(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".
Reply
#3
Thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 4,470 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  I'm getting a syntax error very early on in my code and I can't quite figure it out. liloliveoil 1 2,690 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 2,619 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Annuity function for school - syntax error peterp 2 2,866 Oct-12-2020, 10:34 PM
Last Post: jefsummers
  Invalid syntax error, where? tucktuck9 2 4,266 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  Raise an exception for syntax error sbabu 8 4,763 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 5,272 Jan-25-2020, 03:40 PM
Last Post: jefsummers
  Self taught , (creating a quiz) syntax error on my array DarkAlchemyXEX 9 5,964 Jan-10-2020, 02:30 AM
Last Post: ichabod801
  Syntax Error: Invalid Syntax in a while loop sydney 1 4,850 Oct-19-2019, 01:40 AM
Last Post: jefsummers
  Question about running comparisons through loop from input value Sunioj 2 3,196 Oct-15-2019, 03:15 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020