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")
  
# The else statement is only reached if the for loop
# has run all the way through without breaking

Example 2: if syntax in python

variable_name = input("y/n? >> ")
if variable_name == "y":
	print("That's good! :) ")
# note the double equal signs. only a single equal sign will receive a Syntax error blah blah blah message.
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

#Conditionals statements in python
#'=' conditionals statements
a = 123
b = 123

if(a==b):
  print('True')
  
#<, > conditionals statements

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')