This class shows you how to write if/else if/ else statements with numbers and strings.
- 00:00 Intro
- 04:19 Python Conditions
- 10:37 If Else Statement
- 17:00 Else If
- 22:42 Using AND OR, and creating a Dynamic Script with randint function
- 28:59 Detect Text in Strings
- 32:51 Final Thoughts
if-else.py
var_num = 50
if var_num > 100:
print('Thats a BIG NUMBER')
else:
print('Thats a small number')
if-elif-else.py
var_num = 700
if var_num > 50 and var_num <= 100:
print('Not BIG, or small')
elif var_num > 100:
print('Thats a BIG number')
else:
print('Thats a small number')
if-else-module.py
import random
var_num = random.randint(0,150)
print(var_num)
if var_num > 50 and var_num <= 100:
print('Not BIG, or small')
elif var_num > 100:
print('Thats a BIG number')
else:
print('Thats a small number')
if var_num < 50 or var_num > 100:
print('The number is on the edge')
else:
print('The number is in the middle')
if-else-string.py
var_string = 'sue'
message = 'hello bob. how are you doing?'
if var_string in message:
print(message)
else:
print('The message is not for you')
if var_string not in message:
print('try again later')
else:
print('I hope you liked your message')
Be the first to comment