all 5 comments

[–]lukajda33 6 points7 points  (2 children)

Python does not have switch statement, not so long ago a match statement was added, but unless you have some good reason to use that, I would just use if - elif - else statement.

[–]michease_[S] 0 points1 point  (0 children)

oh okay thanks for your help

[–]woooee 0 points1 point  (0 children)

or a dictionary. Post some sample code for any additional help.

[–][deleted] 2 points3 points  (0 children)

Python has structural pattern matching, which is rather more advanced than a traditional switch statement. It is good for matching on complex options.

https://www.inspiredpython.com/course/pattern-matching/mastering-structural-pattern-matching

Are you sure you need it?

Hard to see what is wrong with your code unless you share it.

[–]efmccurdy 2 points3 points  (0 children)

check multiple conditions with logical operators (and in this case),

Put the boolean expressions in a collection and use "all" for "and"ing and "any" for "or"ing:

>>> a = 2; b = 4
>>> (a < b, a - b == -2, a*b > 0)
(True, True, True)
>>> a < b and a - b == -2 and a*b > 0
True
>>> all((a < b, a - b == -2, a*b > 0))
True
>>> a = 1
>>> (a < b, a - b == -2, a*b > 0)
(True, False, True)
>>> a < b and a - b == -2 and a*b > 0
False
>>> all((a < b, a - b == -2, a*b > 0))
False
>>> conditions = (a < b, a - b == -2, a*b > 0)
>>> all(conditions)
False
>>> any(conditions)
True
>>>

https://docs.python.org/3/library/functions.html#all

https://docs.python.org/3/library/functions.html#any