作为一名非常新的Python编写者,我正在制作一个计算器,该计算器应该询问用户一系列问题,然后确定他们一生中花在筷子上的大约总金额。我目前正在尝试循环一系列问题,以便可以将答案用于计算总数。
while brand != ''
brand = str(input('Enter a brand of chapstick you use: '))
brand = brand.title()
brand_cost = float(input('How much does', brand, 'chapstick cost? $'))
brand_quantity = int(input('How many', brand, 'chapstick(s) do you own? '))
brand_regularly = int(input('How many', brand, 'chapsticks do you finish per year? '))
brand_since = int(input('At what age did you first buy', brand, 'Chapstick? '))
您可以将所有值附加到列表中,以便在使用完输入值后最后计算它们。如下所示:
完成用户操作后,将有4个列表,其中包含可用于进行计算的所有输入值。