Home > database >  How do I get the program to repeat itself after the total is printed? (Like a new person is ordering
How do I get the program to repeat itself after the total is printed? (Like a new person is ordering

Time:10-08

def main():
#this is the part that I want to restart after the total is given
        print("Welcome to static burger!")
        print("Please answer each question with y or n.")

   #The bill and food variables 
    bill = 0.00
    hb = 8.00
    cb = 6.00
    cs = 5.00
    fry = 2.00
    cdmts = 1.00
    
#The code adds up the user's order than prints his/her total.
    first = (input("Would you like a hamburger?"))
    if first == 'y':
        (input('with cheese?'))
        if first == 'y':
    
         bill  = (hb   2.00)
        else:
            bill  = hb
    second = (input("Would you like a cheeseburger?"))
    if second == 'y':
        bill  = cb
    third = (input("Would you like a chicken sandwich?"))
    if third == 'y':
        bill  = cs
    fourth = (input("Would you like a fries?"))
    if fourth == 'y':
        bill  = fry
    fifth = (input("Would you like condiments?"))
    if fifth == 'y':
        bill  = cdmts
    else:
        bill = bill
    tip = 1.2
    total = bill * tip
    
    bill * 0.2
    #total of the users order
    print("Your total is $" "{:.2f}".format(total), "dollars")
    

#After this thankyou is printed, I want the code to restart as if a new person is making their order. print("Thank you for your business!") main()

#TLDR I just want to know which loop to use to make my keep restarting and making the user choose new items and get a new total.

CodePudding user response:

Add a while True:a statement from where you want your code to repeat.


    def main():
#this is the part that I want to restart after the total is given
    print("Welcome to static burger!")
    print("Please answer each question with y or n.")

   #The bill and food variables 
    bill = 0.00
    hb = 8.00
    cb = 6.00
    cs = 5.00
    fry = 2.00
    cdmts = 1.00
    
#The code adds up the user's order than prints his/her total.
    while True:
        first = (input("Would you like a hamburger?"))
        if first == 'y':
            (input('with cheese?'))
            if first == 'y':
        
             bill  = (hb   2.00)
            else:
                bill  = hb
        second = (input("Would you like a cheeseburger?"))
        if second == 'y':
            bill  = cb
        third = (input("Would you like a chicken sandwich?"))
        if third == 'y':
            bill  = cs
        fourth = (input("Would you like a fries?"))
        if fourth == 'y':
            bill  = fry
        fifth = (input("Would you like condiments?"))
        if fifth == 'y':
            bill  = cdmts
        else:
            bill = bill
        tip = 1.2
        total = bill * tip
        
        bill * 0.2
        #total of the users order
        print("Your total is $" "{:.2f}".format(total), "dollars")
        print()

main()

To break the loop, you can add a condition and use the break statement.

  • Related