所以当我尝试调用我的customer_name()时,函数会一直调用我的while循环。似乎总是调用我的phone_number,然后循环进入customer_name循环。然后,如果我在循环播放时接受phone_number,则调用pizza_menu的while循环。我已经尝试过多次解决这个问题,但没有运气,有人能帮助我吗?此外,我尝试将所有变量customer_name,phone_number等添加到最后打印出来但它一直给我“未定义”我想将它们全部添加到列表中然后在最后打印出来。我希望有人可以帮助我,我真的很感激。我不被允许上课,因为我们还没有学到这一点。 使用python 3.3
premium_pizzas = ["Supreme Cheese", "The Legendary pizza", "Pentakill supreme", "Teeto shroomo supreme", "The volcanic rengar", "Cheese and Ham" , "Vegetriano" ]
gourmet_pizzas = ["Flame Gorilla", "Snazzy chicken", "Intergalactic BBQ", "BBQ Chicken", "Hellfire"]
num_pizzas = -1
def customer_name():
customer_name =""
while customer_name == "":
try:
customer_name = str(input("Please enter your name"))
except:
print("error you must enter something! (cannot be a number)")
else:
user_info()
def delivery_details():
delivery_address = ""
while delivery_address =="":
try:
delivery_address = str(input("please enter your delivery address"))
except:
print("error you must enter something!")
phone_number = 0
while (phone_number <0) or (phone_number <7):
try:
phone_number = int(input("Please enter your phone number:\n\t"))
except:
print("Phone number must be integer only(No only.)")
else:
pizza_list()
def pizza_list():
num_pizzas = -1
while( num_pizzas <= 0 ) or ( num_pizzas > 5 ):
try:
num_pizzas = int( input( 'How many pizzas would you like (max of 5):'))
except:
print('Invalid Input')
pizza_dict = {"premium_pizza_price":8.50, "gourmet_pizza_price":5.00, "selected_pizzas":0, "num_premium_pizzas":0, "num_gourmet_pizzas":0}
print('\n==Premium Pizzas==\n')
for i in range (0,len(premium_pizzas)):
print (str(i+1) + '. ' + premium_pizzas[i])
print('\n==Gourmet Pizzas==\n')
for i in range (0,len(gourmet_pizzas)):
print (str(i+1) + '. ' + gourmet_pizzas[i])
print('\nEnter "next" to move on.\n')
while(True):
if( num_pizzas == 0 ):
break;
try:
selected = input('Select Your Premium Pizza: ')
if(selected == 'next'):
break;
else:
selected = int(selected)
if(selected<=0) or (selected > len(premium_pizzas)):
print('Invalid Input')
else:
pizza_dict['num_premium_pizzas']+=1
num_pizzas -=1
except:
print('Invalid Input')
print(' ')
while(True):
if( num_pizzas == 0 ):
break;
try:
selected = input('Select Your Gourmet Pizza: ')
if(selected == 'next'):
break;
else:
selected = int(selected)
if(selected<=0) or (selected > len(gourmet_pizzas)):
print('Invalid Input')
else:
pizza_dict['num_gourmet_pizzas']+=1
num_pizzas -=1
except:
print('Invalid Input')
def user_info():
get_user_info = ""
while not get_user_info == "1":
get_user_info =str(input("Press 1 for delivery press\nPress 2 for pickup\n\t:"))
if get_user_info == "1":
delivery_details()
elif get_user_info == "2":
pizza_list()
receipt = [customer_name]
#print('\nTotal number of premium pizzas: ' + str(pizza_dict['num_premium_pizzas']));
#print('Total number of gourmet pizzas: ' + str(pizza_dict['num_gourmet_pizzas']));
#cost = (pizza_dict["num_premium_pizzas"]*pizza_dict['premium_pizza_price'])+(pizza_dict["num_gourmet_pizzas"]*pizza_dict['gourmet_pizza_price']*3.00);
#print('\nTotal cost: ' + str(cost))
customer_name()
#delivery_details()
#geprint('\nTotal number of premium pizzas: ' + str(pizza_dict['num_premium_pizzas']));
答案 0 :(得分:0)
这是因为你的缩进不一致,你的电话号码循环不在一个函数中,所以一旦脚本运行就会立即运行。