Я изо всех сил пытаюсь раздобыть группу переменных строки из массива.Выбор строковой переменной в массиве - Python
Код:
элементов в массиве:
pizzas_with_prices = [("Hawaiian", 8.5), ("Veg Deluxe", 8.5), ("Ham and Cheese", 8.5),("Super Supreme", 8.5), ("Seafood Deluxe", 8.5),("Meatlovers", 11.5), ("Hot 'n' Spicy", 11.5), ("BBQ Chicken and Bacon", 11.5),("Satay Chicken", 11.5)]
Выбор пиццы в массиве:
for n in range(numPizza):
pizza = pizza + [int(input("Choose a pizza: "))]
Для полной стоимости пицц выбранных:
for selected in pizza:
total_price += pizzas_with_prices[selected][1]
print("$%s" % (total_price))
У меня возникли проблемы с получением названий пиццы, выбранных в массиве, но я могу получить общие цены на выбранные пиццы. Спасибо за любую помощь!
Edit:
Всего Код:
pizzas_with_prices = [("Hawaiian", 8.5), ("Veg Deluxe", 8.5), ("Ham and Cheese", 8.5),
("Super Supreme", 8.5), ("Seafood Deluxe", 8.5),
("Meatlovers", 11.5), ("Hot 'n' Spicy", 11.5), ("BBQ Chicken and Bacon", 11.5),
("Satay Chicken", 11.5)]
def menu():
print("Delivery or Pickup?")
print()
print("1] Delivery ($5 charge)")
print("2] Pickup")
print()
option = int(input(">>"))
if option < 1 or option > 2:
print("Only 1 or 2")
print()
if option == 1:
customerName = input("Enter customers name: ")
customerAddress = input("Enter customer Address: ")
customerPhone = input("Enter your phone number: ")
print()
print("Thank you", customerName, "Customers Address is", customerAddress, "and customers phone number is", customerPhone)
print()
orderPizza()
if option == 2:
customerName = input("Enter customers name: ")
print()
orderPizza()
def orderPizza():
numPizza=0
global pizzas_with_prices
Flag = True
while Flag:
try:
numPizza= int(input("How many Pizzas do you want? (MAX 7): "))
if numPizza ==0 or numPizza > 7:
print("Not a correct choice, Try again")
else:
Flag = False
except ValueError:
print("Not a number, Try again")
print()
for index, pizza in enumerate(pizzas_with_prices):
print("%d %s: $%s" % (index, pizza[0], pizza[1]))
pizza=[]
for n in range(numPizza): #covers values from 0 to 9
pizza = pizza + [int(input("Choose a pizza: "))]
print(pizza)
total_price = 0
for selected in pizza:
total_price += pizzas_with_prices[selected][1]
print("$%s" % (total_price))
menu()
Какой язык вы используете (это не Java или C/C++)? –
Извините, забыл упомянуть, что Python изменит название благодаря –
'pizzas_with_prices [selected] [0]' не печатает? – manoj