KButler
KButler

Reputation: 97

updating a return value within a function

The issue i am having is getting the value of a returned item to update from different functions within a main function.

I have tried syntax to see if that changed anything, but I am not sure what needs to happen to get (in this case: the count and total). I have also tried setting the functions = count, total but that returned an error.

def main():
    terminate = False
    print("Welcome to the self-checkout system at Wake-Mart.")

    count, total = scan_prices()
    print('')
    disc = discount(count, total)
    print('')
    promo = promotion(count, total)
    balance = total

def scan_prices():
    total = 0
    count = 0
    prices = float(input("Enter the price of the first item:"))
    while prices > 0:
            count +=1
            total = total + prices
            print("Number of items:", count, "Total:", total)
            prices = float(input("Eneter the price of the next item [or 0 to stop]:"))
            while  prices < 0:
                print("Price cannot be negative.")
                prices = float(input("Eneter the price of the next item [or 0 to stop]:"))
                if prices > 0:
                    count +=1
                    total = total + prices
                    print("Number of items:", count, "Total:", total)
                    prices = float(input("Eneter the price of the next item [or 0 to stop]:"))
                    continue

    return count, total
def discount(count, total):
     if count >= 10:
            print("You've got a 10% discount for buying 10 items or more.")
            total = total * .9
            print("Number of items:", count, "Total:", total)
     return total
def promotion(count, total):
    if total >= 50:
        card = input(print("Do you want to buy a $50 gift card for $40 [y/n]:"))
        if card == 'Y' or 'y':
            print("Thank you for buying a giftcard.")
            count +=1
            total = (total * .9) + 40
            print("Number if items:", count, "Total:", total)
        else:
            print("Thank for your purchases.")
            print("Number if items:", count, "Total:", (total * .9))
    return count, total
main()

I am just wanting the total and count to be updated as I move from one function execution to the next within the main function.

Upvotes: 0

Views: 295

Answers (1)

quamrana
quamrana

Reputation: 39404

It looks like your main should take the return of one function and pass it to the next:

def main():
    terminate = False
    print("Welcome to the self-checkout system at Wake-Mart.")

    count, total = scan_prices()
    print('')
    total = discount(count, total)
    print('')
    count, total = promotion(count, total)
    balance = total

Upvotes: 3

Related Questions