Apr-04-2020, 07:50 AM
Hi, am trying to call a class attribute but am unable to get it to work. When the user inputs the Item.code into a float input, I want to display
"You have selected (Item.name) which is (Item.price). Currently (Item.amount) in stock."
I have read through the basics of Classes on the website, and Inheritance and Overloading. But I can't work out how to refer to the other Item attributes. I can always revert back to just lists, but I know that isn't good code.
Any help would be appreciated.
Code below
"You have selected (Item.name) which is (Item.price). Currently (Item.amount) in stock."
I have read through the basics of Classes on the website, and Inheritance and Overloading. But I can't work out how to refer to the other Item attributes. I can always revert back to just lists, but I know that isn't good code.
Any help would be appreciated.
Code below
class Item: def __init__(self, code, name, price, amount): self.code = code self.name = name self.price = price self.amount = amount class VendingMachine: def __init__(self): self.items = [ Item(1, "Tea", 0.50, 10), Item(2, "Coffee", 1.00, 10), Item(3, "Coke", 1.50, 6), Item(4, "Orange Juice", 1.00, 5) ]