for if python code example
Example 1: python for else
list = [99, 98, 97, 96, 95, 94]
for number in list:
if number == 2:
print("There is a 2 in the list")
break
else:
print("There are no 2's in the list")
Example 2: 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 3: or statement python
if x==1 or y==1:
print(x,y)
Example 4: if statement in python
a = 123
b = 123
if(a==b):
print('True')
a = 2
b = 45
if(a<b):
print('A is smaller than B')
Example 5: if statements python
water = input('Does your creature live underwater?')
if water == 'yes':
print('Your creature lives underwater')
else:
print('Your creature does not live underwater')