American Young Coder (AYC)

AYC logo
Loading Events

« All Events

  • This event has passed.

5:00 PM – Python Object Oriented Programming – Sebastian

April 11, 2023 @ 5:00 pm - 6:00 pm

Today We Did
  1. Started and quickly finished GroceryShoppingCart (great job!)
  2.  Brief introduction to OOP, sneak peak of the following:
    Classes, Attributes, Methods, Constructors, and Objects
  3. In case you need anything, feel free to email me at sebastian@ayclogic.com
Homework
  1. Name your homework APR11_robux_hw, please submit by next Monday.
  2. Homework: Recall your old RobuxShoppingCart assignment:

    menu = """
    What do you want to do: 
    1. Buy hat 100 Robux
    2. Buy hair 150 Robux
    3. VIP Server 500 Robux
    4. Add more Robux
    5. Exit
    Enter your selection: """
    
    shopping_cart = []
    robux = 300
    
    def handle_transaction(price, item_name):
        global robux
        if robux < price:
            print(f"You only have {robux} robux remaining. Therefore you cannot purchase {item_name} for {price} robux.")
        else:
            robux -= price
            print(f"You purchased a {item_name}. You have {robux} robux remaining.")
            shopping_cart.append(item_name)
    
    print(f"Welcome to Robux Bank, you have {robux} robux in the beginning.")
    
    while True:
        selection = input(menu)
        if selection == "5":
            break
        elif selection not in("1","2","3","4","5"):
            print("invalid selection")
        elif selection == "1":
            handle_transaction(100, "Hat")
        elif selection == "2":
            handle_transaction(150, "Hair")
        elif selection == "3":
            handle_transaction(500, "VIP Server")
        elif selection == "4":
            credit_card_number = input("Enter your Credit Card number: ")
            if credit_card_number == "ABCD1234":
                robux += 200
                print(f"Thank you for purchasing 200 Robux. You now have {robux} robux remaining.")
            else:
                print("You have entered an invalid credit card number")
    
    
    print("\nYou have purchased the following items:")
    count = 1
    for item in shopping_cart:
        print(f"{count}. {item.title()}")
        count += 1
    
    print(f"Your remaining Robux balance is {robux} Robux.")

    Try your best to recreate this with two dictionaries:

    – input_name
    – selection_price

    These should map the selection to the name (hat, hair, VIP server, add more robux), and map the selection to the price (100, 150, 500, 200).

Details

Date:
April 11, 2023
Time:
5:00 pm - 6:00 pm
Event Categories:
,
Verified by MonsterInsights