在行继续字符错误后,我得到一个意外的字符

use*_*386 0 python printing character

在此行中的行继续字符错误后,我收到一个意外的字符

 print (\t,"Order total $",format(total, "10.2"),\n\t,"Discount    $",format(disc,"10.2"),\n\t,"Amount Due $",format (due, "10.2"),sep="")
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这意味着什么以及如何解决它?谢谢

def finddiscount(quantity):
        if quantity >= 1 and quantity <= 9:
            discount = 0
        elif quantity >= 10 and quantity <= 19:
            discount = .2
        elif quantity >= 20 and quantity <= 49:
            discount = .30
        elif quantity >= 50 and quantity <= 99:
            discount = .40
        elif quantity >= 100:
            discount = .50
    def calctotal(quantity, price):
        disc = (price*quantity)*finddiscount(quantity)
        total = (price*quantity)
        due = (price*quantity)-(price*quantity)*dicount
        print (\t,"Order total $",format(total, "10.2"),\n\t,"Discount    $",format(disc,"10.2"),\n\t,"Amount Due $",format (due, "10.2"),sep="")
    def main():
        quantity = int(input("How many packages where purchased?"))
        price = float(input("How much is each item?"))
        calctotal(quantity, price)
    main()
Run Code Online (Sandbox Code Playgroud)

Ash*_*ary 5

您忘记在此行的许多项目周围使用引号:

print ("\t","Order total $",format(total, "10.2"),"\n\t","Discount    $",format(disc,"10.2"),"\n\t","Amount Due $",format (due, "10.2"),sep="")
        ^                                           ^                                          ^
Run Code Online (Sandbox Code Playgroud)

另一种格式化方法是使用str.format如下:

print ("\tOrder total $ {:10.2}\n\tDiscount    ${:10.2}\n\tAmount Due ${:10.2}".format(total, disc, due))
Run Code Online (Sandbox Code Playgroud)