if is in python code example
Example 1: if syntax in python
variable_name = input("y/n? >> ")
if variable_name == "y":
print("That's good! :) ")
elif variable_name == "n":
print("That's bad! :( ")
else:
print("You blow up for not following my instructions. Detention forever and get lost!")
Example 2: python if
if num==5:
print("Num equal to 5")
elif num > 5:
print("Num more than 5")
else:
print("Num smaller than 5 but not equal to 5")
Example 3: python how to check in a list
listA = ['Stranger Things', 'S Education', 'Game of Thrones']
if 'Dark' in listA:
print("Yes, 'S Eductation' found in List : ", listA)
else:
print("Nope, 'Dark' not found in the list")
Example 4: how to do if= python
if X=1
if X==1
Example 5: 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?')