如何将列表中的所有数字相乘以显示新列表?

2024-04-19 06:51:31 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,这真的很重要,我只需要有人帮我。我对python非常陌生,所以有很多事情我就是想不通。你知道吗

我正在编写一个程序,要求用户输入菜谱名称和它服务的人数。你知道吗

然后,它要求用户输入有关成分的信息。我创建了一个列表,如下所示。你知道吗

ingredients = []
while True:
 ingredient_name = input("Name your ingredient: ")
 ingredient_quantity: int(input("Write the quantity of your ingredient: "))
 ingredient_unit = input("Write the unit of your ingredient: ")
 ingredients.append((ingredient_name, ingredient_quantity, ingredient_unit))

 cont = input("Continue adding ingredients? [y/n]")
 all_ingredients = " ".join(str(v) for v in ingredients)
 if not cont.lower() in ("y","yes"):
     break

然后程序显示创建的列表。但是,我希望能够要求用户为配方输入一个新的人数,然后将列表中的配料数量乘以这个新人数,以显示新人数的列表。你知道吗

我完全不知道如何做到这一点,所以如果有人能解释它将是如此有益于我!另外,如果这是含糊或不清楚,对不起,我已经尽力解释它在我能做的最好的方式。你知道吗


Tags: ofthe用户name程序列表inputyour