Control Flow with If/Else and Conditional Operators
print("Welcome to Dino Roller Coaster")
height = int(input("What is your height: "))
h = height
if h > 120:
print("You can ride the roller coaster")
else:
print("Sorry, you can't ride the roller coaster")
Odd or Even Exercises
number = int(input("Please type in the number: "))
n = number
if n%2==0:
print(f"The number {n} is even")
elif n%2==1:
print(f"The number {n} is odd")
Nested If Loops and Elif Statement
print("Welcome to Dino Roller Coaster")
height = int(input("What is your height: "))
h = height
if h > 120:
print("You can ride the roller coaster")
age = int(input("What is your age: "))
if age < 18:
print("The price will be $7")
elif age > 18:
print("The price will be $12")
else:
print("Sorry, you can't ride the roller coaster")
BMI 2.0
w = float(input("Type in your weight: "))
weight = w
h = float(input("Type in your height: "))
height = h
BMI = round(weight/height**2)
if BMI < 18.5:
print(f" BMI Score: {BMI} | You're underweight")
elif BMI > 18.5 and BMI < 22.0:
print(f" BMI Score: {BMI} |You're normal")
elif BMI > 25 and BMI < 30:
print(f" BMI Score: {BMI} | You're Overweight")
elif BMI > 30 and BMI < 35:
print(f" BMI Score: {BMI} | You're Obese")
else:
print(f" BMI Score: {BMI} | You're Clinically Obese")
Leap Year Exercise
year = int(input("Which year do you want to put in: "))
divideFour = year/4
divideHun = year/100
divideFourHun = year/400
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print(f"The year {year} is a leap")
else:
print("The year is not a leap")
else:
print(f"The year {year} is a leap")
else:
print("The year is not a leap")
Pizza Order
print("Welcome to Park's Pizzeria")
size = input("What size of pizza do you want [S,M,L]: ")
addPep = input("Do you want to add pepperoni on your pizza? [Y,N]: ")
extraChe = input("Do you want to add extra cheese on your pizza? [Y,N]: ")
SP = 15
MP = 20
LP = 25
addP4SP = 2
addP4MLP = 3
cheese = 1
total = 0
if size == "S":
total += SP
elif size == "M":
total += MP
elif size == "L":
total += LP
if addPep == "Y":
if size == "S":
total += addP4SP
else:
total += addP4MLP
if extraChe == "Y":
total += 1
print(f"Your total will be ${total}")
Logical Operators
Love Calculator
print("Welcome to the Love Calculator")
name1 = input("What's your name: ")
name2 = input("What's their name: ")
combined = name1 + name2
lowercase = combined.lower()
T = lowercase.count("t")
R = lowercase.count("r")
U = lowercase.count("u")
E = lowercase.count("e")
true = T+R+U+E
L = lowercase.count("l")
o = lowercase.count("o")
V = lowercase.count("v")
E2 = lowercase.count("e")
love = L + o + V + E2
loveScore = (true*10) + love
print(f"Your love score is {loveScore}")
Treasure Hunt
print("Welcome to the Treasure Land\\n")
print("Your mission is to find the treasure\\n")
LR = input("Left of Right? ")
if LR == "Right":
print("Game Over")
else:
SW = input("Swim or Wait? ")
if SW == "Swim":
print("Game Over")
else:
Door = input("Which door? [Red, Blue, Yellow]: ")
if Door == "Red" or Door == "Blue":
print("Game Over")
else:
print("You Win!")