I have been trying to make a cash register like code, where the user types in their product name the price and the quantity. I have four products. After doing all the adding for these i need to get the 5% GST and then print out the total amount including the GST. This is what i could come with so far and i am new to python that’s why i don’t know a lot of error and other keywords. I get and ut in everything but when i multiply it says it can’t multiply string and an integer. I tried changing the variable name and did all other stuff but it wouldn’t give a total.
name1 =raw_input('What Item do you have: ')
price1 = float(input('What is the price of your item: '))
quantity1 = float(input('How many are you buying: '))
name2 = raw_input('What Item do you have: ')
price2 = float(input('What is the price of your item: '))
quantity2 = float(input('How many are you buying: '))
name3 = raw_input('What Item do you have: ')
price3 = float(input('What is the price of your item: '))
quantity3 = float(input('How many are you buying: '))
name4= raw_input('What Item do you have: ')
price4 = float(input('What is the price of your item: '))
quantity4 = float(input('How many are you buying: '))
sum_total= (price1 * quantity1), (price2 * quantity2), (price3 * quantity3), (price4 * quantity4),
print(' %.2f ' % quantity1+quantity2+quantity3,' X ', name1+name2+name3,' @ %.2f ' %
price1+ price2+price3,' = %.2f ' % total)
divv = sum_total / 100
percent = divv * 0.05
gst = sum_total + percent
print('The suggested gst is %.2f '% percent )
print('That will be a total of: %.2f '% gst)
It can be simplified a lot.
Your code for asking about products could be simplified to this:
which will make your code more flexible and modular.
Total sum can be calculated like this (assuming
productscontains result of the above function):Suggested GST, if I understand you correctly, is:
You can also print list of products with prices and quantities: