<p>将<code>dish_codeslist</code>中的第二个<code>if</code>语句更改为:</p>
<pre><code>if (1 < a < 10):
for i in range(1,a+1):
print("v"+str(i)," -", vietnamese_dishes[i-1])
print("\n\nPlease choose another dish by indicating the code that we provide")
print("\nYou may order the same dish as before, if you want")
print("\nIf you do not choose an existing dish we will choose one for you")
return
</code></pre>
<p>编辑:</p>
<pre><code> if (1 < a < 10):
for i in range(1,a+1):
print("v"+str(i)," -", vietnamese_dishes[i-1])
print("\n==================================")
if (1 < b < 10):
for i in range(1,b+1):
print("i"+str(i)," -", italian_dishes[i-1])
print("\n\nPlease choose another dish by indicating the code that we provide")
print("\nYou may order the same dish as before, if you want")
print("\nIf you do not choose an existing dish we will choose one for you")
</code></pre>
<p>编辑2:</p>
<pre><code>if (1 < a < 10 and 1 < b <10):
for i in range(1,a+1):
print("v"+str(i)," -", vietnamese_dishes[i-1])
print("\n==================================\n")
for i in range(1,b+1):
print("i"+str(i)," -", italian_dishes[i-1])
print("\n==================================\n")
print("\n\nPlease choose another dish by indicating the code that we provide")
print("\nYou may order the same dish as before, if you want")
print("\nIf you do not choose an existing dish we will choose one for you")
return
</code></pre>
<p>编辑3:</p>
<pre><code>def dish_codeslist():
a = len(vietnamese_dishes)
b = len(italian_dishes)
dish_dict = {}
print("\n\nAll the available dishes are")
print("\n==================================")
if (a == 1):
print("v"+str(a)," -", vietnamese_dishes[0])
print("\n\nPlease choose another dish by indicating the code that we provide")
print("\nYou may order the same dish as before, if you want")
print("\nIf you do not choose an existing dish we will choose one for you")
return
if (1 < a < 10 and 1 < b <10):
for i in range(1,a+1):
print("v"+str(i)," -", vietnamese_dishes[i-1])
dish_dict["v"+str(i)] = (vietnamese_dishes[i-1],vietnamese_dish_prices[i-1])
print("\n==================================\n")
for i in range(1,b+1):
print("i"+str(i)," -", italian_dishes[i-1])
dish_dict["i"+str(i)] = (italian_dishes[i-1],italian_dish_prices[i-1])
print("\n==================================\n")
return dish_dict
def choose_dish(dish_dict):
print("\n\nPlease choose another dish by indicating the code that we provide")
print("\nYou may order the same dish as before, if you want")
print("\nIf you do not choose an existing dish we will choose one for you")
choice = input("Provide the dish code here (MUST BE a letter and a number) ==> ")
if choice in dish_dict.keys():
print(f"*** TRACE: dish {dish_dict[choice][0]} price {dish_dict[choice][1]} ")
else:
print("You did not enter a valid choice, we will suggest a dish for you")
import random
dish = random.choice([*dish_dict.values()])
print("*** TRACE: dish {dish[0]} price {dish[1]} ")
#### Start
codes_setup()
dish_dict = dish_codeslist()
choose_dish(dish_dict)
</code></pre>