Skip to the content.

3.6/3.7 Hacks

Popcorn and Homework hacks for 3.6/3.7

#Homework Hack for 3.6
def assess_numbers(a, b):
    if a == b:
        print("The two numbers are identical.")
    elif a > b:
        print(f"{a} is the greater number.")
    else:
        print(f"{b} is the greater number.")

first_number = float(input("Please enter the first number: "))
second_number = float(input("Please enter the second number: "))

assess_numbers(first_number, second_number)

Please enter the first number:  1
Please enter the second number:  1


The two numbers are identical.
def assess_numbers(a, b):
    if a == b:
        print("The two numbers are identical.")
    elif a > b:
        print(f"{a} is the greater number.")
    else:
        print(f"{b} is the greater number.")

first_number = float(input("Please enter the first number: "))
second_number = float(input("Please enter the second number: "))

assess_numbers(first_number, second_number)

Please enter the first number:  1
Please enter the second number:  2


2.0 is the greater number.
#Homework Hack for 3.7

Not able to be run (Pseudocode)

  1. INPUT exam_score
  2. INPUT attendance_percentage
  3. IF exam_score >= 60 THEN
    • IF attendance_percentage >= 75 THEN
      • PRINT “Student passes the class.”
    • ELSE
      • PRINT “Student fails due to low attendance.”
  4. ELSE
    • PRINT “Student fails due to low exam score.”
#Python delivery speed
def calculate_shipping(weight, delivery_speed):
    if weight <= 5:  # Weight in pounds
        if delivery_speed == "standard":
            cost = 5.00
        elif delivery_speed == "express":
            cost = 10.00
        else:
            cost = "Invalid delivery speed."
    elif weight <= 20:
        if delivery_speed == "standard":
            cost = 10.00
        elif delivery_speed == "express":
            cost = 20.00
        else:
            cost = "Invalid delivery speed."
    else:
        if delivery_speed == "standard":
            cost = 20.00
        elif delivery_speed == "express":
            cost = 40.00
        else:
            cost = "Invalid delivery speed."
    
    return cost

weight = float(input("Enter the weight of the package (in pounds): "))
speed = input("Choose delivery speed (standard/express): ")
shipping_cost = calculate_shipping(weight, speed)
print(f"Shipping cost: {shipping_cost}")

Enter the weight of the package (in pounds):  10
Choose delivery speed (standard/express):  standard


Shipping cost: 10.0
#python tickets
def ticket_price(age, is_student):
    if age < 12:
        price = 5.00  # Child ticket price
    elif 12 <= age < 65:
        price = 10.00  # Adult ticket price
    else:
        price = 7.00  # Senior ticket price
    
    if is_student:
        price *= 0.9  # students have the pric e

    return price

# Example usage
age = int(input("Enter your age: "))
is_student = input("Are you a student? (yes/no): ").strip().lower() == "yes"
price = ticket_price(age, is_student)
print(f"Your ticket price is: ${price:.2f}")