我用过
current_pizza_list = ('pizza_' + str(current_pizza) + '[1]')
生成列表名称和位置。但我想在输入中使用此列表
pizza_ammount = input('How many', exec(current_pizza_list) ,' pizzas would you like:')
这不起作用,我不是100%确定exec函数的工作原理。 任何帮助都会很棒。
pizza_1 = ['8.00','Pepperoni']
pizza_2 = ['8.00','Hawaiian']
pizza_3 = ['8.00','Meat Lovers']
pizza_4 = ['8.00','Classic Cheese']
while True:
print('What sort of pizza would you like')
print('Input 1 for ' , pizza_1[1],' , $',pizza_1[0])
print('Input 2 for ' , pizza_2[1],' , $',pizza_2[0])
print('Input 3 for ' , pizza_3[1],' , $',pizza_3[0])
print('Input 4 for ' , pizza_4[1],' , $',pizza_4[0])
current_pizza = input('What pizza would you like:')
current_pizza_list = ('pizza_' + str(current_pizza) + '[1]')
pizza_ammount = input('How many', exec(current_pizza_list) ,' pizzas would you like:')
break