Суммирование переменных в цикле while для python

Моя программа задумана как виртуальный Макдональдс. Все работает нормально, но мне нужна помощь с одним из методов суммирования. В нижней части этой программы я подсчитал общее количество сборов и т. д. Теперь мне нужно подсчитать, сколько клиентов прошло через программу. Это сложно, потому что для клиентов нет установленного числа. Эта программа запускается в цикле while, и общее количество клиентов полностью зависит от пользователя. Как подсчитать общее количество клиентов?

num1 = 4.87
num2 = 5.03
num3 = 5.50
num4 = 9.45
num5 = 1.29
num6 = 2.19
num7 = 2.29
tax = 0.0565
customer = 0
nextcustomer = "yes"
dailytax = 0
dailysubtotal = 0
dailyfinalbill = 0
dailynum_customers = 0

while nextcustomer != "no":
    amtgiven = 0
    change = 0
    quantity = 0
    foodprice = 0
    totalprice = 0
    billtax = 0
    finalbill = 0
    itemnum = 0
    print "Welcome to Virtual McDonald's!"
    print "Item:                     Meal/item:                          Price:"
    print "1                          Big Mac Meal                        4.87"
    print "2                          Quarter Pounder Meal                5.03"
    print "3                          Chicken Nuggets Meal (5 piece)      5.50"
    print "4                          ChickenNuggets Meal (10 piece)      9.45"
    print "5                          Apple Pie                           1.29"
    print "6                          Large Drink                         2.19"
    print "7                          Large Fries                         2.29"

    customer = raw_input ("Would you like to order? (If not type no)")
    while customer != "no":

        while itemnum != -1: 
            itemnum = input("Enter the item you would like to purchase! ")
            if itemnum == -1:
                break
            quantity = input("How many of this item do you want? ")

            if itemnum == 1:
                foodprice = quantity * num1
                totalprice += foodprice

            elif itemnum == 2:
                foodprice = quantity * num2
                totalprice += foodprice

            elif itemnum == 3:
                foodprice = quantity * num3
                totalprice += foodprice

            elif itemnum == 4:
                foodprice = quantity * num4
                totalprice += foodprice

            elif itemnum == 5:
                foodprice = quantity * num5
                totalprice += foodprice

            elif itemnum == 6:
                foodprice = quantity * num6
                totalprice += foodprice

            elif itemnum == 7:
                foodprice = quantity * num7
                totalprice += foodprice

        billtax = totalprice * tax
        finalbill = totalprice + billtax        
        dailytax = dailytax + billtax
        dailysubtotal = dailysubtotal + totalprice
        dailyfinalbill = dailyfinalbill + finalbill

        print "Your total bill without tax is... ", round(totalprice,2)
        print "Your total tax is... ", round(billtax,2)
        print "Your final bill is... ", round(finalbill,2)
        amtgiven = input("How much do you want to pay with? ")
        change = amtgiven - finalbill
        print "Your change is... ", round(change,2)
        break
    nextcustomer = raw_input("Is there another customer? (yes or no) ") 

print "The total amount of sales without added tax recieved today is...",round(dailysubtotal,2)
print "The total amount of taxes received today is...",round(dailytax,2)
print "The total amount of sales with added tax recieved today is...",round(dailyfinalbill,2)
print dailynum_customers

person Christian Braverman    schedule 29.01.2013    source источник
comment
что означает общий клиент, уникальный или повторяющийся клиент может быть подсчитан?   -  person Black Diamond    schedule 29.01.2013


Ответы (1)


Добавьте numCustomers = 0 вверху.

Также измените это:

while nextcustomer != "no":
    amtgiven = 0

к этому:

while nextcustomer != "no":
    numCustomers += 1
    amtgiven = 0

В конце добавьте это:

print 'total customers:', numCustomers
person inspectorG4dget    schedule 29.01.2013
comment
Похоже, dailynum_customers был предназначен для этой цели, ИМО. Но в остальном, я думаю, это все. - person BobS; 29.01.2013
comment
@InspectorG4dget amtgiven используется для другого расчета, поэтому я не могу его использовать. - person Christian Braverman; 29.01.2013