Question
Can someone help me create a Python 3 program that has 2 classes? I have to create a python program that asks the user for
Can someone help me create a Python 3 program that has 2 classes?
I have to create a python program that asks the user for the name of the item, the price of the item, if the item is taxable, and if they want to add another item. If the user says they want to add another item, the program will loop and ask the user again for the item name, price, if it is taxable, and if they want to add another item. The program will continue to do this until the user does not want to add another item. Once the user does NOT want to add another item, the program will calculate the subtotal of all the items, and then will calculate the total WITH the tax (the items that are taxed). I'm new to programming so I'm still trying to understand the gist of it.
Here is what I have so far (I'm stuck):
import datetime class Items: def __init__(self,name,price,taxable): #not too familiar with how to use "__init__" self.__name = name self.__price = price self.__taxable = taxable def __str__(self): #also confused about this return self.__name return self.__price return self.__taxable def getPrice(self): name = str(input('Enter item name: ')) price = float(input('Enter item price: ')) return price def getTax(self): taxable = input('Is the item taxable (yes/no)? ') tax_rate = 0.06 #PA's tax rate I think if taxable == "yes": taxed = tax_rate * price #multiplies tax rate with item price else: taxed = 1 * price #this will just return the item price return taxed pass class Receipt: def __init__(self): #idk what to do about this def __str__(self): #idk what to do about this def addItem(self): add = input("Would you like to add another item (yes/no)? ") return add pass item_price = getPrice() if __name__=="__main__": print('Welcome to Receipt Creator') while add != "no": print('-----', str(datetime.datetime.now()), '-----' ) print(name, ":", item_price) print("Subtotal:", sum(name)) #takes the sum of item price without tax print("Tax:", sum(taxed)) #takes the sum of the tax amount print("Total:", sum(taxed) + sum(name)) #prints the total cost with the tax
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started