Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could an "also if" be implemented in Python?

I want to implement something conceptually like the following:

if condition1:
    action1()
also if condition2:
    action2()
also if condition3:
    action3()
also if condition4:
    action4()
also if condition5:
    action5()
also if condition6:
    action6()
else:
    print("None of the conditions was met.")

What would be a reasonable and clear way of implementing logic like this? How could an else be bound to multiple if statements? Would I be forced to create a boolean to keep track of things?

like image 905
d3pd Avatar asked Nov 29 '22 01:11

d3pd


1 Answers

I would suggest:

if condition1:
    action1()
if condition2:
    action2()
...
if not any(condition1, condition2, ...):
    print(...)
like image 176
jonrsharpe Avatar answered Dec 09 '22 09:12

jonrsharpe