I am trying to make a method in a class in Python that will take values from a a dictionary and return the original price's, the total amount of tax and the total of all items plus tax.
like this,
iPad.....$799.99
Surface..$999.99
Tax......$108.00
Total....$1907.98
my code is below and my methods for tax are def sales_tax and def calculated_tax.
What I have tried:
class Invoice:
def __init__(self, invoice_id, customer_id, last_name, first_name, phone_number, address):
self.invoice_id = invoice_id
self.customer_id = customer_id
self.last_name = last_name
self.first_name = first_name
self.phone_number = phone_number
self.address = address
self.items_with_price = {}
def add_item(self, product, price):
if product not in self.items_with_price:
self.items_with_price["iPad"] = 799.99
self.items_with_price["Surface"] = 999.99
def sales_tax(self, price):
sales_tax = .06
return items_with_price * sales_tax
def calculated_tax(self, price):
self.calculated_tax = sales_tax * items_with_price
def display_totals(self, price):
print('iPad', price)
print('Surface', price)
sales_tax = calculated_tax(price)
print('Tax', calculated_tax)
print('Total', price + calculated_tax)
def __str__(self):
return(self.items_with_price)
invoice = Invoice(1, 123, '1313 Disneyland Dr, Anaheim, CA 92802', 'Mouse', 'Minnie', '555-867-5309')
invoice.add_item({'iPad': 799.99})
invoice.add_item({'Surface': 999.99})
invoice.create_invoice()