python best way to write complex if and else statements code example
Example 1: if statements equals same value python
if min(A, B, C, D) >= 2:
print A, B, C, D
Example 2: conditional block python
a = 1
b = 2
if a < b:
print("a is less than b") #This will run since 1 is less than 2
elif a > b:
print("a is greater than b")
else:
print("a is equal to b")
Example 3: python if
def e(x):
if x == "Sunny" and x == "sunny":
print('Remember your sunglasses!')
elif x == "Rainy" and x == "rainy":
print('Do not forget your umbrella!')
elif x == 'Thunderstorm' or x == 'thunderstorm' or x =='Stormy' or x == 'stormy':
print('Stay Home!')
x = input('What is the weather?')
Example 4: if and elif
if test expression:
Body of if
elif test expression:
Body of elif
else:
Body of else