CS50 taqueria python 任务 - eof 停止程序的输入

问题描述 投票:0回答:1

这是我的代码:

def main():

    dict = {
    "Baja Taco": 4.00,
    "Burrito": 7.50,
    "Bowl": 8.50,
    "Nachos": 11.00,
    "Quesadilla": 8.50,
    "Super Burrito": 8.50,
    "Super Quesadilla": 9.50,
    "Taco": 3.00,
    "Tortilla Salad": 8.00
    }
    cost = 0.0
    while True:
        try:
            item = input("Item: ").title()
            if item in dict:
                cost = cost + dict[item]
                print(f"Total: ${format(cost, ".2f")}")
        except EOFError:
            print()
            break

main()

Cs50 说预期的退出代码应该是 0,但它是 1,我不知道为什么会这样,也不知道该怎么做才能使它正确。 但是当我自己尝试该程序时,一切都工作得很好,我还可以使用控制 D 来停止该程序 - 正如它应该的那样。

python cs50 eof
1个回答
0
投票

此行中不能使用相同的引号。

您的代码:

print(f"Total: ${format(cost, ".2f")}")

应该是:

print(f"Total: ${format(cost, '.2f')}")

这可能是退出代码 1 的原因。

© www.soinside.com 2019 - 2024. All rights reserved.