1

好的,所以我对编程很陌生。我已经开始自学 python-3.2,并且正在尝试编写一个程序来显示任何餐馆账单如果有 15% 的小费和 20% 的小费。我不断得到:

Traceback (most recent call last):   
  File "/home/marian/restaurantbilltotal.py", line 6, in <module>     
    print(fifteen ("Plus a 15% tip: "))
TypeError: 'int' object is not callable tip

我写的代码是:

#Restaurant bill total

bill = int(input("Restaurant bill total: "))

fifteen = (bill // 100) * 15 + bill
print(fifteen ("Plus a 15% tip: "))

twenty = (bill // 100) * 20 + bill
print(twenty ("Plus a 20% tip: "))

input("\n\nPress the enter key to exit.")

请帮忙,但请记住,我才刚刚开始学习如何编程:-)。谢谢。

4

3 回答 3

1

fifteen是一个整数值。你试图通过调用它来对待它就像一个函数:

print(fifteen ("Plus a 15% tip: "))

也许您想在文本之后打印它:

print("Plus a 15% tip:", fifteen)

同样的错误适用于twenty,以类似的方式更正它:

print("Plus a 20% tip:", twenty)
于 2013-08-18T08:28:45.630 回答
0

你应该写:

print ('Plus 15% tip:' , str(fifteen))

在您的代码中,它被解释为:fiften('Plus 15% tip: ')就像它是一个函数一样。

于 2013-08-18T08:29:45.650 回答
0
bill = int(input("Restaurant bill total: "))

fifteen = (bill * 0.15)

twenty = (bill * 0.20)

print("Your Actual bill : ", bill)
print("Bill with 15% additional charge : ", bill+fifteen)
print("Bill with 20% additional charge : ", bill+twenty)

input("\n\nPress the enter key to exit.")
于 2013-08-18T08:33:47.887 回答