Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Jack Cummins
Jack Cummins
17,417 Points

how to restart while loop

My code is:

import sys
import random


def resturaunt_open():
    if rand == 1:
        print("That resturaunt is closed right now.") # I want to restart the loop right here
def food_money(food1, food2, food3, food4, food5, money, money2, money3, money4, money5):
    food = input("Do you want to get " + food1 + ", " + food2 + ", " + food3 + ", " + food4 + ", or " + food5 + "? ").lower()
    if food == food1:
        print("Your food wil cost $" + money)
    elif food == food2:
        print("Your food wil cost $" + money2)
    elif food == food3:
        print("Your food wil cost $" + money3)
    elif food == food4:
        print("Your food wil cost $" + money4)
    elif food == food5:
        print("Your food wil cost $" + money5)
    else:
        print("That food was not one of your options.")
        sys.exit()
def choose_resturaunt():
    global resturaunt
    if resturaunt == "mcdonalds":
        resturaunt_open()
        food_money("a big mac","grilled chicken"," an egg mcmuffin","a happy meal","mcnuggets", "3.99", "4.59", "3.79", "3.00", "4.49")
    elif resturaunt == "jimmy's seafood":
        resturaunt_open()
        food_money("fish","shrimp","clams", "muscles","lobster", "8.50", "13.50", "9.50", "10.00", "26.00")
    elif resturaunt == "mickey's diner":
        resturaunt_open()
        food_money("a stack of 3 pancakes","oatmeal","a hamburger","a cheseburger", "a ham and cheese sandwhich","5.49","3.79","6.99", "7.19","5.19")
    elif resturaunt == "john's steakhouse":
        resturaunt_open()
        food_money("a crab cake","shrimp with sauce","beef and bacon","steak with sauce", "a lobster blt","17.00","23.00","15.00", "18.00","25.00")
    elif resturaunt == "joe's foodcourt":
        resturaunt_open()
        food_money("a footlong bacon and chese sub","a steakburger","a hamburger","a cheseburger", "fish with sauce","4.99","5.79","4.99", "4.99","6.19")
    elif resturaunt == "beacon street cafe":
        resturaunt_open()
        food_money("coffee","an omlet","croque madame","a turkey and pesto sandwhich","a loaded burger","4.19","4.59","9.00","8.50","5.50")
    elif resturaunt == "alex's bakery":
        resturaunt_open()
        food_money("plain bagel","an everything bagel","a blueberry muffin","a croissant","a baugette","1.29","1.49","2.39","2.19","3.19")
    elif resturaunt == "ihop":
        resturaunt_open()
        food_money("5 chocolate pancakes","10 plain pancakes","a belgian waffle","6 french toast slices","3 blueberry pancakes","6.49","10.19","5.19","6.59","6.99")
    else:
        print("That was not one of your options.")
def want_quit():
    input("Press 'q' to quit out of this application. Press enter to choose which resturaunt you want to go to again.")

while True:
    rand = random.randint(1, 1)
    resturaunt = input("Do you want to go to McDonalds, Jimmy's seafood, Mickey's diner, John's steakhouse, Joe's food court, Beacon Street Cafe, Alex's bakery, or IHOP? ").lower()
    choose_resturaunt()

How can I restart the loop where I put my comment? Please help!

Thank you so much in advance! Jack

P.S. Note: My comment is in the first function in the code. The resturaunt_open() function. The comment is in green.

1 Answer

John Lack-Wilson
John Lack-Wilson
8,181 Points

Hi Jack, the function you have placed your comment in does not appear to be within your while True loop. What is it that you're wanting to do?