Homework Hack 1
IF grade >= 60
{
DISPLAY "You Pass!"
IF grade >= 90
{
DISPLAY "A"
}
ELSE IF grade >= 80
{
DISPLAY "B"
}
ELSE IF grade >= 70
{
DISPLAY "C"
}
ELSE IF grade >= 60
{
DISPLAY "D"
}
}
IF grade < 60
{
DISPLAY "You didn't pass, F!"
}
Homework Hack 2
valid_inputs = ["Standard","Express"]
try:
weight = int(input("What is the weight of your package?"))
except ValueError:
print("That's not a valid weight!")
try:
speed = input("Choose a delivery speed: Standard, Express")
if speed not in valid_inputs:
raise ValueError("Invalid input: You can only enter (Standard, Express)")
except ValueError as e:
print(e)
if weight >= 20:
if speed == "Standard":
print("Your cost is $20!")
elif speed == "Express":
print("Your cost is $25!")
else:
if speed == "Standard":
print("Your cost is $15!")
elif speed == "Express":
print("Your cost is $20!")
Homework Hack 3
age = int(input("What is your age?"))
parent = input("Are you with a parent?")
if age < 18:
if parent == "yes":
print("Your child's ticket is free!")
else:
print("Your ticket costs $5!")
else:
print("Your ticket costs $10!")
Challenge Hack
def get_positive_integer(prompt):
while True:
user_input = input(prompt)
try:
value = int(user_input)
if value <= 0:
print("The number must be positive. Please try again.")
else:
return value
except ValueError:
print("Invalid input. Please enter a valid positive integer.")
side1 = get_positive_integer("What is the length of side one?")
side2 = get_positive_integer("What is the length of side two?")
side3 = get_positive_integer("What is the length of side three?")
if side1 + side2 > side3 and side2 + side3 > side1 and side1 + side3 > side2:
if side1 == side2 == side3:
print("You have an equilateral triangle!")
elif side1 == side2 or side2 == side3 or side3 == side1:
print("You have an isosceles triangle!")
else:
print("You have a scalene triangle!")
else:
print("Make sure your sides make a triangle!")