В чем проблема в цикле for моего кода python для пиццы не работает? - PullRequest
0 голосов
/ 29 апреля 2019

Привет! Я создал этот базовый код на Python, который запрашивает нужную пиццу, включая начинки

Я попытался изменить циклы, но выдает ошибку, если работает, не даетсоответствующий ответ.

'' '

print("Hello.\nWelcome to Pizzeria World")
Cheese_Types = ['Mozzarella', 'Parmesan', 'Ricotta', 'Feta', 'Blue Veined', 'Cheddar', 'Gouda', 'Cottage', 'Goat', 'Halloumi', 'Kalari', 'Scamorza', 'Bocconcini', 'Mascarpone', 'Gorgonzola', 'Grana Padano', 'Kalimpong']
Veg_Toppings = ['Cappsicum', 'Olives', 'Onions', 'Jalapeno', 'Mushroom', 'Babycorn', 'Potato', 'Paneer']
Non_Veg_Toppings = ['Chicken Tikka', 'Chicken CHilly', 'Chicken Crispy', 'Chicken Masala', 'Chicken Hara Bhara', 'Chicken Kashmiri', 'Fish Fry', 'Prawn', 'Mutton', 'Ham', 'Bacon', 'Meat Sausage']
Crust_Types = ['Cheese', 'Sausage', 'Simple']
Breads = ['Thin','Thick', 'Fluffy']
Sizes = ['Mini', 'Small', 'Medium', 'Large', 'Extra large', 'Super Sized']

print("\nBread Types")
e=1
for Bread in Breads:
    print( str(int(e)) + ". " + Bread + " Bread.")
    int(str(e))       
    e=e+1
print("Please Select your choice of Bread. Please ensure your input is numerical as per the given Menu.")
while True:
    g = input()
    if(g.isdigit()):
        g=int()
        g=g-1
        while True:
            if(g>=0 and g<3):
                break
            else:
                print("Please enter a value from the menu")
        break
    else:
        print("Please enter a numerical value")

print("\nCrust Types")
d=1
for Crust_Type in Crust_Types:
    print( str(int(d)) + ". " + Crust_Type + " Crust.")
    int(str(d))       
    d=d+1
print("Please Select your choice of Crust Type. Please ensure your input is numerical as per the given Menu.")
while True:
    r = input()
    if(r.isdigit()):
        r=r-1
        while True:
            if(r>=0 and r<3):
                break
            else:
                print("Please enter a value from the menu")
        break
    else:
        print("Please enter a numerical value")

print("\nPizza Sizes")
f=1
for Size in Sizes:
    print( str(int(f)) + ". " + Size + " Pizza.")
    int(str(f))       
    f=f+1
print("Please Select your choice of Pizza Size. Please ensure your input is numerical as per the given Menu.")
while True:
    h = input()
    if(h.isdigit()):
        h=h-1
        while True:
            if(h>=0 and h<6):
                break
            else:
                print("Please enter a value from the menu")
        break
    else:
        print("Please enter a numerical value")

print("\nTypes of Cheese")
a=1
for Cheese_Type in Cheese_Types:
    print( str(int(a)) + ". " + Cheese_Type + " Cheese.")
    int(str(a))       
    a=a+1
print("Please Select your choice for the type of Cheese. Please ensure your input is numerical as per the given Menu.")
while True:
    i = input()
    if(i.isdigit()):
        i=i-1
        while True:
            if(i>=0 and i<17):
                break
            else:
                print("Please enter a value from the menu")
        break
    else:
        print("Please enter a numerical value")

print("\nVegetarian Toppings")
b=1
for Veg_Topping in Veg_Toppings:
    print( str(int(b)) + ". " + Veg_Topping + ".")
    int(str(b))       
    b=b+1
print("Please Select your choice for the Vegetarian Toppings. Please ensure your input is numerical as per the given Menu." )
while True:
    j = input()
    if(j.isdigit()):
        j=j-1
        while True:
            if(j>=0 and j<8):
                l=Veg_Toppings[j] + " "
                while True:
                    print("Do you want any more Vegetarian Toppings?")
                    k = input()
                    k=k.title()
                    if(k == "Yes"):
                        print("Please Select your choice for the Vegetarian Toppings. Please ensure your input is numerical as per the given Menu." )
                        m = input()
                        m=m-1
                        l=l+Veg_Toppings[m]+" "
                    else:
                        break
            break
        else:
            print("Please enter a value from the menu")
        break
    else:
        print("Please enter a numerical value")

print("\nNon-Vegetarian Toppings")
c=1
for Non_Veg_Topping in Non_Veg_Toppings:
    print( str(int(c)) + ". " + Non_Veg_Topping + ".")
    int(str(c))       
    c=c+1
print("Please Select your choice for the Non Vegetarian Toppings. Please ensure your input is numerical as per the given Menu." )
while True:
    n = input()
    if(n.isdigit()):
        n=n-1
        while True:
            if(n>=0 and n<12):
                o=Non_Veg_Toppings[n] + " "
                while True:
                    print("Do you want any more Non Vegetarian Toppings?")
                    p = input()
                    p=p.title()
                    if(p == "Yes"):
                        print("Please Select your choice for the Non Vegetarian Toppings. Please ensure your input is numerical as per the given Menu." )
                        q = input()
                        q=q-1
                        o=o+Non_Veg_Toppings[q]+" "
                    else:
                        break
            break
        else:
            print("Please enter a value from the menu")
        break
    else:
        print("Please enter a numerical value")
Pizza = "You have ordered a " + Breads[g] + " Bread " + Crust_Types[r] + " Crust " + Sizes[h] + " Pizza with " + Cheese_Types[i] + " Cheese and " + l + o + "."
print(Pizza)
'''

Это простой код, но он не будет работать так, как должен работать.Я также попытался удалить некоторый код.Я также попытался изменить + на -.

1 Ответ

0 голосов
/ 29 апреля 2019

Ваш код не очень читабелен, и я сделал минимальные изменения, чтобы он работал, я бы посоветовал взять его отсюда и поработать над вашим кодом, чтобы сделать его лучше.

Некоторые ошибки, которые я обнаружил в вашемкод.

  1. Нет необходимости во внешней внешней петле while True, которую вы добавили в любой из вариантов.
  2. Во многих местах вы не присвоили int(variable)фактическая переменная
  3. Также переменные l и o должны быть определены вне цикла, чтобы сделать их доступными для операторов печати. ​​
print("Hello.\nWelcome to Pizzeria World")
Cheese_Types = ['Mozzarella', 'Parmesan', 'Ricotta', 'Feta', 'Blue Veined', 'Cheddar', 'Gouda', 'Cottage', 'Goat', 'Halloumi', 'Kalari', 'Scamorza', 'Bocconcini', 'Mascarpone', 'Gorgonzola', 'Grana Padano', 'Kalimpong']
Veg_Toppings = ['Cappsicum', 'Olives', 'Onions', 'Jalapeno', 'Mushroom', 'Babycorn', 'Potato', 'Paneer']
Non_Veg_Toppings = ['Chicken Tikka', 'Chicken CHilly', 'Chicken Crispy', 'Chicken Masala', 'Chicken Hara Bhara', 'Chicken Kashmiri', 'Fish Fry', 'Prawn', 'Mutton', 'Ham', 'Bacon', 'Meat Sausage']
Crust_Types = ['Cheese', 'Sausage', 'Simple']
Breads = ['Thin','Thick', 'Fluffy']
Sizes = ['Mini', 'Small', 'Medium', 'Large', 'Extra large', 'Super Sized']

print("\nBread Types")
e=1
for Bread in Breads:
    print( str(int(e)) + ". " + Bread + " Bread.")
    int(str(e))
    e=e+1
print("Please Select your choice of Bread. Please ensure your input is numerical as per the given Menu.")

g = input()
if(g.isdigit()):
    g=int(g)
    g=g-1
    while True:
        if(g>=0 and g<3):
            break
        else:
            print("Please enter a value from the menu")
else:
    print("Please enter a numerical value")

print("\nCrust Types")
d=1
for Crust_Type in Crust_Types:
    print( str(int(d)) + ". " + Crust_Type + " Crust.")
    d = int(str(d))
    d=d+1
print("Please Select your choice of Crust Type. Please ensure your input is numerical as per the given Menu.")

r = input()
if(r.isdigit()):
    r = int(r)
    r=r-1
    while True:
        if(r>=0 and r<3):
            break
        else:
            print("Please enter a value from the menu")
else:
    print("Please enter a numerical value")

print("\nPizza Sizes")
f=1
for Size in Sizes:
    print( str(int(f)) + ". " + Size + " Pizza.")
    f = int(str(f))
    f=f+1
print("Please Select your choice of Pizza Size. Please ensure your input is numerical as per the given Menu.")

h = input()
if(h.isdigit()):
    h = int(h)
    h=h-1
    while True:
        if(h>=0 and h<6):
            break
        else:
            print("Please enter a value from the menu")

else:
    print("Please enter a numerical value")

print("\nTypes of Cheese")
a=1
for Cheese_Type in Cheese_Types:
    print( str(int(a)) + ". " + Cheese_Type + " Cheese.")
    int(str(a))
    a=a+1

print("Please Select your choice for the type of Cheese. Please ensure your input is numerical as per the given Menu.")

i = input()
if(i.isdigit()):
    i = int(i)
    i=i-1
    while True:
        if(i>=0 and i<17):
            break
        else:
            print("Please enter a value from the menu")
else:
    print("Please enter a numerical value")

print("\nVegetarian Toppings")
b=1
for Veg_Topping in Veg_Toppings:
    print( str(int(b)) + ". " + Veg_Topping + ".")
    b = int(str(b))
    b=b+1
print("Please Select your choice for the Vegetarian Toppings. Please ensure your input is numerical as per the given Menu." )

j = input()
l = " "
if(j.isdigit()):
    j = int(j)
    j=j-1
    while True:
        if(j>=0 and j<8):
            l=Veg_Toppings[j] + " "
            while True:
                print("Do you want any more Vegetarian Toppings?")
                k = input()
                k=k.title()
                if(k == "Yes"):
                    print("Please Select your choice for the Vegetarian Toppings. Please ensure your input is numerical as per the given Menu." )
                    m = input()
                    m = int(m)
                    m=m-1
                    l=l+Veg_Toppings[m]+" "
                else:
                    break
        break
else:
    print("Please enter a value from the menu")


print("\nNon-Vegetarian Toppings")
c=1
for Non_Veg_Topping in Non_Veg_Toppings:
    print( str(int(c)) + ". " + Non_Veg_Topping + ".")
    c = int(str(c))
    c=c+1
print("Please Select your choice for the Non Vegetarian Toppings. Please ensure your input is numerical as per the given Menu." )

n = input()
o = " "
if(n.isdigit()):
    n = int(n)
    n=n-1
    while True:
        if(n>=0 and n<12):
            o=Non_Veg_Toppings[n] + " "
            while True:
                print("Do you want any more Non Vegetarian Toppings?")
                p = input()
                p=p.title()
                if(p == "Yes"):
                    print("Please Select your choice for the Non Vegetarian Toppings. Please ensure your input is numerical as per the given Menu." )
                    q = input()
                    q = int(q)
                    q=q-1
                    o=o+Non_Veg_Toppings[q]+" "
                else:
                    break
        else:
            print("Please enter a value from the menu")
        break

else:
    print("Please enter a numerical value")

Pizza = "You have ordered a {} Bread {} Crust {} Pizza with {} Cheese and {} {}.".format(Breads[g],Crust_Types[r], Sizes[h], Cheese_Types[i], l , o)
print(Pizza)

Вывод теперьвыглядит так.

Hello.
Welcome to Pizzeria World

Bread Types
1. Thin Bread.
2. Thick Bread.
3. Fluffy Bread.
Please Select your choice of Bread. Please ensure your input is numerical as per the given Menu.
1

Crust Types
1. Cheese Crust.
2. Sausage Crust.
3. Simple Crust.
Please Select your choice of Crust Type. Please ensure your input is numerical as per the given Menu.
1

Pizza Sizes
1. Mini Pizza.
2. Small Pizza.
3. Medium Pizza.
4. Large Pizza.
5. Extra large Pizza.
6. Super Sized Pizza.
Please Select your choice of Pizza Size. Please ensure your input is numerical as per the given Menu.
1

Types of Cheese
1. Mozzarella Cheese.
2. Parmesan Cheese.
3. Ricotta Cheese.
4. Feta Cheese.
5. Blue Veined Cheese.
6. Cheddar Cheese.
7. Gouda Cheese.
8. Cottage Cheese.
9. Goat Cheese.
10. Halloumi Cheese.
11. Kalari Cheese.
12. Scamorza Cheese.
13. Bocconcini Cheese.
14. Mascarpone Cheese.
15. Gorgonzola Cheese.
16. Grana Padano Cheese.
17. Kalimpong Cheese.
Please Select your choice for the type of Cheese. Please ensure your input is numerical as per the given Menu.
1

Vegetarian Toppings
1. Cappsicum.
2. Olives.
3. Onions.
4. Jalapeno.
5. Mushroom.
6. Babycorn.
7. Potato.
8. Paneer.
Please Select your choice for the Vegetarian Toppings. Please ensure your input is numerical as per the given Menu.
1
Do you want any more Vegetarian Toppings?
No

Non-Vegetarian Toppings
1. Chicken Tikka.
2. Chicken CHilly.
3. Chicken Crispy.
4. Chicken Masala.
5. Chicken Hara Bhara.
6. Chicken Kashmiri.
7. Fish Fry.
8. Prawn.
9. Mutton.
10. Ham.
11. Bacon.
12. Meat Sausage.
Please Select your choice for the Non Vegetarian Toppings. Please ensure your input is numerical as per the given Menu.
1
Do you want any more Non Vegetarian Toppings?
No
You have ordered a Thin Bread Cheese Crust Mini Pizza with Mozzarella Cheese and Cappsicum  Chicken Tikka .
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...