Python中运用while循环点单并统计在list中

CSDN问答 2022-05-14 15:37:59 阅读数:965

Python统计循环List运用

s1mple = [('apple', 2.10), ('milk', 4.50), ('banana', 10.50)]

点单代码为:(input)
Enter order for apple:
Enter order for milk:
Enter order for Krusty:

将以上三个input放进list,如[1,1,1,]
运用def,并menu为s1mple
效果图如下

img




采纳答案:
def get_order(menu:list) -> list:  return [int(input(f'Enter order for {i[0]}:')) for i in menu]sample = [('apple', 1.50),('orange',2.90)]check = get_order(sample)print(check)

版权声明:本文为[CSDN问答]所创,转载请带上原文链接,感谢。 https://ask.csdn.net/questions/7711907