'Failing Output in Python
The goal is to create a class object for a grocery list then output the list. Output should say something like "Item 1...Enter the item name:" but with the input's item show as well. Here is my current code:
class ItemToPurchase:
def __init__(self):
self.item_name = "none"
self.item_price = 0.0
self.item_quantity = 0
def print_item_cost(self, item_name, item_price, item_quantity):
return (item_quantity * item_price)
if __name__ == "__main__":
items=[]
for i in range(2):
item_name=input("Enter the item name:\n")
item_price=float(input("Enter the item price:\n"))
item_quantity = int(input("Enter the item quantity:\n"))
items.append(item_name)
items.append(item_price)
items.append(item_quantity)
one = items[0:3:1]
two = items[3:6:1]
objs1 = ItemToPurchase()
res1 = objs1.print_item_cost(one[0], one[1], one[2])
objs2 = ItemToPurchase()
res2 = objs2.print_item_cost(two[0], two[1], two[2])
result = res1+res2
print("TOTAL COST:\n",result)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
