Hi I writing a Python program to track and calculate the amount of money each of 8 customers spends on 12 grocery items. The code below works fine but The program also must congratulate the customer who spends the most money and offer that customer a $50 shopping spree.How can I do the last part (congratulate the customer who spends more money???)PLEASE SOMEBODY HELP ME!!!I HAVE TRIED SEVERAL TIMES BUT I GIVE UP
HERE IS THE CODE:
def receipt():
for i in range(8):
name = raw_input("Please enter a name: ")
print
item1 = raw_input("Input the name of the item: ")
price1 = input("Input the price of the item: $")
print
item2 = raw_input("Input the name of the item: ")
price2 = input("Input the price of the item: $")
print
item3 = raw_input("Input the name of the item: ")
price3 = input("Input the price of the item: $")
print
item4 = raw_input("Input the name of the item: ")
price4 = input("Input the price of the item: $")
print
item5 = raw_input("Input the name of the item: ")
price5 = input("Input the price of the item: $")
print
item6 = raw_input("Input the name of the item: ")
price6 = input("Input the price of the item: $")
print
item7 = raw_input("Input the name of the item: ")
price7 = input("Input the price of the item: $")
print
item8 = raw_input("Input the name of the item: ")
price8 = input("Input the price of the item: $")
print
item9 = raw_input("Input the name of the item: ")
price9 = input("Input the price of the item: $")
print
item10 = raw_input("Input the name of the item: ")
price10 = input("Input the price of the item: $")
print
item11 = raw_input("Input the name of the item: ")
price11 = input("Input the price of the item: $")
print
item12 = raw_input("Input the name of the item: ")
price12 = input("Input the price of the item: $")
print
Total = price1 + price2 + price3 + price4 + price5 + price6 + price7 + price8 + price9 + price10 + price11 + price12
Tax = Total * 0.07
GTotal = Total + Tax
print
print "%14s %14s" % ("Items", "Prices")
print
print "%14s %14s" % (item1, price1)
print "%14s %14s" % (item2, price2)
print "%14s %14s" % (item3, price3)
print "%14s %14s" % (item4, price4)
print "%14s %14s" % (item5, price5)
print "%14s %14s" % (item6, price6)
print "%14s %14s" % (item7, price7)
print "%14s %14s" % (item8, price8)
print "%14s %14s" % (item9, price9)
print "%14s %14s" % (item10, price10)
print "%14s %14s" % (item11, price11)
print "%14s %14s" % (item12, price12)
print
print "Subtotal: $", Total
print "Tax: $", Tax
print
print "Total: $", GTotal
print
print "Thank you for shopping with us, ",name
print
print
print

receipt()

Recommended Answers

All 7 Replies

Please wrap your code in the code-tag

I'm not going to sit here and guess what your program is trying to do by looking at a syntax incorrect script.

def receipt():
for i in range(8):
name = raw_input("Please enter a name: ")
print
item1 = raw_input("Input the name of the item: ")
price1 = input("Input the price of the item: $")
print
item2 = raw_input("Input the name of the item: ")

price2 = input("Input the price of the item: $")

print
item3 = raw_input("Input the name of the item: ")

price3 = input("Input the price of the item: $")
print
item4 = raw_input("Input the name of the item: ")
price4 = input("Input the price of the item: $")
print
item5 = raw_input("Input the name of the item: ")
price5 = input("Input the price of the item: $")
print
item6 = raw_input("Input the name of the item: ")
price6 = input("Input the price of the item: $")
print
item7 = raw_input("Input the name of the item: ")
price7 = input("Input the price of the item: $")
print
item8 = raw_input("Input the name of the item: ")
price8 = input("Input the price of the item: $")
print
item9 = raw_input("Input the name of the item: ")
price9 = input("Input the price of the item: $")
print
item10 = raw_input("Input the name of the item: ")
price10 = input("Input the price of the item: $")
print
item11 = raw_input("Input the name of the item: ")
price11 = input("Input the price of the item: $")
print
item12 = raw_input("Input the name of the item: ")
price12 = input("Input the price of the item: $")
print
Total = price1 + price2 + price3 + price4 + price5 + price6 + price7 + price8 + price9 + price10 + price11 + price12
Tax = Total * 0.07
GTotal = Total + Tax
print
print "%14s %14s" % ("Items", "Prices")
print
print "%14s %14s" % (item1, price1)
print "%14s %14s" % (item2, price2)
print "%14s %14s" % (item3, price3)
print "%14s %14s" % (item4, price4)
print "%14s %14s" % (item5, price5)
print "%14s %14s" % (item6, price6)
print "%14s %14s" % (item7, price7)
print "%14s %14s" % (item8, price8)
print "%14s %14s" % (item9, price9)
print "%14s %14s" % (item10, price10)
print "%14s %14s" % (item11, price11)
print "%14s %14s" % (item12, price12)
print
print "Subtotal: $", Total
print "Tax: $", Tax
print
print "Total: $", GTotal
print
print "Thank you for shopping with us, ",name
print
print
print

receipt()

class Customer(object):
    def __init__(self, name):
        self.name = name
        self.items = {}
    
    def gettotal(self):
        tot = 0
        for price in self.items.values():
            tot += price
        return tot

def main():
    print "Enter 'quit' when being asked for customer's name to quit the program"
    print "Enter 'done' when being asked for item name to move on to next customer"
    print ""
    
    customers = []
    while True:
        name = raw_input("Please enter customer's name: ")
        if name == "quit":
            break
        cust = Customer(name)
        customers.append(cust)
        while True:
            item = raw_input("Item name: ")
            if item == "done":
                break
            while True:
                price = raw_input("Price of %s: " % item)
                try:
                    price = float(price)
                    break
                except:
                    print "Price must be numeric"
            cust.items[item] = price
    
    if not customers:
        print "There are no customers to win the shopping spree"
        return
    
    winner = None
    maxspent = 0
    for cust in customers:
        spent = cust.gettotal()
        if spent > maxspent:
            maxspent = spent
            winner = cust
    
    print ""
    print "Congratulations %s!" % winner.name
    print "You have just won a $50 shopping spree for spending $%s." % maxspent

if __name__ == "__main__":
    main()

I don't get your question and, what you really want to do.

If it is what I think you can just check if the name of the current customer is the name of the winner and display the message.

But fot it to be logic, you ahould be saving all those values in file, and showing the message the next time the customer would log.

Thank you so much bro!!!now my program is been completed. You are a genious!!!!thanks a lot!!!!

Please close the thread if you think the problem is solved.

You might also want to think about your user input

name = raw_input("Please enter customer's name: ")
if name == "quit":

which will fail if the person enters a leading or trailing space around the 'quit'. Instead, I suggest if 'quit' == name.strip()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.