Python Forum
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax error in def
#4
You have another problem. A statement like:
if s != '7' or '14' or '30':
will not do what you expect, since '14' and '30' will be interpreted as True (not False, None or zero),
and the whole statement will always be true.

You should code:
if s not in ('7', '14', '30'):

Or more traditionally:

if s != '7' and s != '14' and s !='30:
Reply


Messages In This Thread
Syntax error in def - by Beatenberg - Oct-09-2017, 01:56 AM
RE: Syntax error in def - by ichabod801 - Oct-09-2017, 02:29 AM
RE: Syntax error in def - by Beatenberg - Oct-09-2017, 02:43 AM
RE: Syntax error in def - by miltmobley - Oct-09-2017, 03:01 AM
RE: Syntax error in def - by Beatenberg - Oct-09-2017, 03:12 AM
RE: Syntax error in def - by Larz60+ - Oct-09-2017, 09:45 AM
RE: Syntax error in def - by Beatenberg - Oct-09-2017, 10:05 AM
RE: Syntax error in def - by Larz60+ - Oct-09-2017, 11:30 AM
RE: Syntax error in def - by ichabod801 - Oct-09-2017, 01:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,406 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,046 Oct-30-2020, 05:03 AM
Last Post: deanhystad
  Unspecified syntax error hhydration 1 2,054 Oct-25-2020, 10:45 AM
Last Post: ibreeden
  Annuity function for school - syntax error peterp 2 2,038 Oct-12-2020, 10:34 PM
Last Post: jefsummers
  Invalid syntax error, where? tucktuck9 2 3,460 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  Raise an exception for syntax error sbabu 8 3,290 Feb-10-2020, 01:57 AM
Last Post: sbabu
  syntax error: can't assign to operator liam 3 4,102 Jan-25-2020, 03:40 PM
Last Post: jefsummers
  Self taught , (creating a quiz) syntax error on my array DarkAlchemyXEX 9 4,417 Jan-10-2020, 02:30 AM
Last Post: ichabod801
  If Statements and Comparisons returns a syntax error DarkAlchemyXEX 2 2,493 Jan-02-2020, 01:25 PM
Last Post: DarkAlchemyXEX
  Syntax Error: Invalid Syntax in a while loop sydney 1 4,131 Oct-19-2019, 01:40 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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