Popcorn Hack/Homework 3.6
Hack #1 - Psuedo Code
START
INPUT Exam1, Exam2, AttendancePercentage
IF Exam1 >= 50 AND Exam2 >= 50 THEN
IF AttendancePercentage >= 75 THEN
PRINT "Student passes the class."
ELSE
PRINT "Student fails due to low attendance."
ENDIF
ELSE
PRINT "Student fails due to low exam scores."
ENDIF
END
Hack #2
# Input: weight of the package and delivery speed
weight = float(input("Enter the weight of the package (kg): "))
speed = input("Choose delivery speed (standard/express): ")
# Decide shipping cost based on weight and speed
if weight < 5:
if speed == "standard":
shipping_cost = 5
elif speed == "express":
shipping_cost = 10
else:
if speed == "standard":
shipping_cost = 10
elif speed == "express":
shipping_cost = 20
print(f"Shipping cost: ${shipping_cost}")
Hack #3
# Input: age of the person and whether they are a student
age = int(input("Enter your age: "))
is_student = input("Are you a student (yes/no)? ").lower()
# Determine ticket price based on age
if age < 12:
ticket_price = 5
elif age <= 17:
ticket_price = 10
elif age <= 64:
ticket_price = 15
else:
ticket_price = 8
# Apply student discount if applicable
if is_student == "yes":
ticket_price -= 2
print(f"Ticket price: ${ticket_price}")
Hack #4
# Function to determine the type of triangle
def triangle_type():
# Prompt user for the sides of the triangle
a = float(input("Enter the length of the first side: "))
b = float(input("Enter the length of the second side: "))
c = float(input("Enter the length of the third side: "))
# Input validation: check if all sides are positive numbers
if a > 0 and b > 0 and c > 0:
# Check if the sides form a valid triangle (Triangle Inequality Theorem)
if (a + b > c) and (a + c > b) and (b + c > a):
# Further classify the type of triangle
if a == b == c:
print("This is an Equilateral Triangle (all sides are equal).")
elif a == b or b == c or a == c:
print("This is an Isosceles Triangle (two sides are equal).")
else:
print("This is a Scalene Triangle (no sides are equal).")
else:
print("The sides do not form a valid triangle.")
else:
print("Invalid input! All sides must be positive numbers.")
# Call the function
triangle_type()