有人能帮我用Python来解决这个问题吗?非常感谢!
这是我遇到的难题。
你今天的购物单上有什么?(假设用户输入是:笔、书、文件夹。我希望它能够复制输出,为每个答案提出一个问题。)
钢笔的估计费用是多少?在这里输入估计成本:书的估计成本是多少?在这里输入估计成本:文件夹的估计成本是多少?在此输入估计成本:
笔、书、文件夹的估计费用总额为:$xx.xx
我希望这不是太令人费解的解释。谢谢你的帮助!
发布于 2018-11-06 05:23:58
在python3中,它可以通过以下方法来完成。
items_str = input('What is on your shopping list today? (Enter elements separated by a comma) ') #take input from the user
items = items_str.replace(" ", "") #to remove whitespaces
items = items.split(',') #creating an array of the items
total = 0
for item in items:
total = total + int(input("What is the estimated cost for {0}? Enter estimated cost here: ".format(item)))
print("Total estimated cost for ", items_str, " is ", total)https://stackoverflow.com/questions/53166014
复制相似问题