when in python code example
Example 1: python if statement
usrinput = input(">> ")
if usrinput == "Hello":
print("Hi")
elif usrinput == "Bye":
print("Bye")
else:
print("Okay...?")
Example 2: 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')
Example 3: python 2.7 else if
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
Example 4: python 2.7 else if
#!/usr/bin/python
var = 100
if var == 200:
print "1 - Got a true expression value"
print var
elif var == 150:
print "2 - Got a true expression value"
print var
elif var == 100:
print "3 - Got a true expression value"
print var
else:
print "4 - Got a false expression value"
print var
print "Good bye!"
Example 5: 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")