代码之家  ›  专栏  ›  技术社区  ›  JoshingYou

我无法运行此程序[已关闭]

  •  -4
  • JoshingYou  · 技术社区  · 7 年前
    # Tipper Program
    # User enters the bill total and the program computes two amounts,
    # a 15 percent tip and a 20 percent tip
    
    print("\t\t\t **  **  **  **  **  **  **  **  **  **")
    
    print("\n\t\t\t\t    Tip Calculator")
    
    print("\n\t\t\t **  **  **  **  **  **  **  **  **  **")
    
    bill = input("\nPlease enter your restaurant's bill total: ")
    
    tip_15 = bill * 0.15
    
    tip_20 = bill * 0.20
    
    float(print("\n\nA 15% tip for this bill comes out to ", tip_15))
    float(print("\nA 20% tip for this bill comes out to ", tip_20))
    
    
    input("\n\nPress the enter key to exit.")
    

    在我输入账单总数后,应用程序一直关闭。有什么解决这个问题的建议吗?

    1 回复  |  直到 7 年前
        1
  •  3
  •   AlanK    7 年前

    当您要求用户输入时,需要将该值转换为浮点值,然后再将其乘以0.15和0.20

    bill = float(input("\nPlease enter your restaurant's bill total: "))
    

    另外,你的最后两行不应该被转换成浮点数

    print("\n\nA 15% tip for this bill comes out to: ", tip_15)
    print("\nA 20% tip for this bill comes out to: ", tip_20)