此代码需要允许输入最多3个想要的物品,并打印所有物品的总成本。我对这一切都是新手,需要我能得到的所有建议。我不能把总数打印出来。
pie = 2.75
coffee = 1.50
icecream = 2.00
while choice:
    choice01 = raw_input("What would you like to buy? pie, coffee, icecream, or nothing?")
    if choice01 == "nothing":
        break
    choice02 = raw_input("What would you like to buy? pie, coffee, icecream, or nothing?")
    if choice02 == "nothing":
        break
    choice03 = raw_input("What would you like to buy? pie, coffee, icecream, or nothing?")
    if choice03 == "nothing":
        break
    cost = choice01+choice02+choice03
    print "Your total is: ${0}" .format(cost)发布于 2015-06-22 11:33:40
看起来你根本不需要三个选择。考虑以下代码
pie = 2.75
coffee = 1.50
icecream = 2.00
cost = 0
while True:
    choice01 = 0
    choice01 = raw_input("What would you like to buy? pie, coffee, icecream, or nothing?")
    if choice01 == "nothing":
        break
    elif choice01=="coffee":
        choice01 = coffee
    elif choice01=="pie":
        choice01 = pie
    elif choice01=="icecream":
        choice01==icecream
    else:
        choice01=0
    cost+=choice01
print "Your total is: ${0}" .format(cost)https://stackoverflow.com/questions/30971683
复制相似问题