- Day 3 Goals
- if/else statements
- Modulo
- Nested if/else and elif statements
- Coding Exercise: BMI Calculator Version 2
- Multiple if statements
- Coding Practice: Pizza Order
- Logical Operators
- Project: Treasure Island
My BMI Calculator V2
weight = 70
height = 1.85
bmi = weight / (height ** 2)
print(bmi)
if bmi < 18.5:
print("Underweight")
elif bmi < 25:
print("Normal Weight")
else:
print("Overweight")
# I note that in Angela's example she has the if/elif/else the opposite way around.
# I have not found any errata in my code, the weights appear to be identified correctly
# if bmi >= 25:
# print("overweight")
# elif bmi >= 18.5:
# print("normal weight")
# else:
# print("Overweight")
My pizza order
print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M or L: ").lower()
pepperoni = input("Do you want pepperoni on your pizza? Y or N: ").lower()
extra_cheese = input("Do you want extra cheese? Y or N: ").lower()
cost = 0
# Calculate the base cost
if size == "s":
cost += 15
elif size == "m":
cost += 20
else:
cost += 25
# Calculate the cost of the pepperoni
if pepperoni == "y":
if size == "s":
cost += 2
else:
cost += 3
# Calculate the cost of the extra cheese
if extra_cheese == "y":
cost += 1
# Print the bill
if size == "s":
print("\nyou ordered a small pizza $15 with the following toppings")
if pepperoni == "y":
print("Pepperoni + $2")
else:
print("No pepperoni")
if extra_cheese == "y":
print("Extra cheese + $1")
if size == "m":
print("\nyou ordered a medium pizza with the following toppings")
if pepperoni == "y":
print("Pepperoni + $3")
else:
print("No pepperoni")
if extra_cheese == "y":
print("Extra cheese +$1")
else:
print("No extra cheese")
if size == "l":
print("\nyou ordered a large pizza with the following toppings")
if pepperoni == "y":
print("Pepperoni + $3")
else:
print("No pepperoni")
if extra_cheese == "y":
print("Extra cheese +$1")
else:
print("No extra cheese")
print(f"\nYour final bill is: ${cost}.")
My Treasure Island game
print(r'''
*******************************************************************************
| | | |
_________|________________.=""_;=.______________|_____________________|_______
| | ,-"_,="" `"=.| |
|___________________|__"=._o`"-._ `"=.______________|___________________
| `"=._o`"=._ _`"=._ |
_________|_____________________:=._o "=._."_.-="'"=.__________________|_______
| | __.--" , ; `"=._o." ,-"""-._ ". |
|___________________|_._" ,. .` ` `` , `"-._"-._ ". '__|___________________
| |o`"=._` , "` `; .". , "-._"-._; ; |
_________|___________| ;`-.o`"=._; ." ` '`."\ ` . "-._ /_______________|_______
| | |o ; `"-.o`"=._`` '` " ,__.--o; |
|___________________|_| ; (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._ " `".o|o_.--" ;o;____/______/______/____
/______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
*******************************************************************************
''')
print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.")
choice = input('you are at a crossroads which way do you go (L) left or (R) right').lower()
if choice == 'l':
choice2 = input("well done! you arrived at a lake. Would you like to (S) swim or (W) wait").lower()
if choice2 == 'w':
choice3 = input("You arrive at a house with 3 doors."
"One red, one yellow and one blue. Which colour do you choose - type the colour?").lower()
if choice3 == 'red':
print("It's a room full of fire. Game Over")
elif choice3 == 'yellow':
print("You found the treasure. You Win!")
elif choice3 == 'blue':
print("You enter a room of beasts. Game Over.")
else:
print("You chose a door that doesn't exist. Game Over.")
else:
print("you are attacked by a trout. Game Over")
elif choice == 'r':
print("You made the wrong choice turning right - Game Over")
else:
print("Your inability to follow instructions means you met a horrible death at the hands of the barbarian army")