简体   繁体   English

我的python比萨代码的for循环中有什么问题?

[英]What is the problem in the for loop of my python pizza code not working?

Hi I have created this basic python code which asks for the favourable pizza people want including the toppings 嗨,我已经创建了这个基本的python代码,要求包括浇头的人们想要的有利披萨

I have tried modifying the loops but it gives an error, if it works, it doesn't give an appropriate answer. 我已经尝试修改循环,但它给出了一个错误,如果它有效,它没有给出一个合适的答案。

''' “””

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)
'''

It is a simple code but it won't work as it should work. 这是一个简单的代码,但它不起作用,因为它应该工作。 I also tried removing some code. 我也尝试删除一些代码。 I also tried changing the + to -. 我也尝试将+更改为 - 。

Your code is not very readable, and I have done minimal changes to make it work, I would suggest taking it from here and working on your code to make it better. 你的代码不是很易读,而且我做了很少的改动才能使它工作,我建议你从这里开始并使用你的代码来改进它。

Some errors I found in your code. 我在您的代码中发现的一些错误。

  1. No need of the external outer while True loop you have added in any of the choices. 不需要外部外部, while True在任何选择中添加了while True循环。
  2. At a lot of places, you have not assigned int(variable) to an actual variable 在很多地方,你没有将int(variable)分配给实际变量
  3. Also the variables l and o need to be defined outside the loop to make it accessible for the print statements. 还需要在循环外定义变量lo ,以使其可用于print语句。
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)

The output now looks like. 输出现在看起来像。

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 .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM