American Young Coder (AYC)

Loading Events

« All Events

  • This event has passed.

3 PM – Python Object Oriented Programming – Sebastian

July 22, 2023 @ 3:00 pm - 4:00 pm

Today We Did
  1. Introduction to object oriented programming
  2. class: a blueprint for an object made up of methods and attributes
  3. method: a function belonging to a class
  4. attribute: a variable belonging to a class that starts with “self.”
  5. constructor: a method called __init__ which is called when class is instantiated, AND we usually create all attributes here
  6. object: an instance of a class which has unique data (unique attributes)
  7. In case you need anything, feel free to email me at sebastian@ayclogic.com
Homework
  1. Name your homework JUL22_robux_dictionary_hw, please submit by next Friday.
  2. Homework: Recall our old RobuxShoppingCart program.  Change RobuxShoppingCart to use dictionary. This is very similar to ShoppingCart using dictionary.

Old code:

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.")

Details

Date:
July 22, 2023
Time:
3:00 pm - 4:00 pm
Event Categories:
,
Verified by MonsterInsights