对于python 3.2,'int'对象不可调用

时间:2013-08-18 08:26:52

标签: python callable

好的,所以我对编程很陌生。我开始自学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.")

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

3 个答案:

答案 0 :(得分:1)

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

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

也许你想在文字之后打印它:

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

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

print("Plus a 20% tip:", twenty)

答案 1 :(得分:0)

你应该写:

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

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

答案 2 :(得分: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.")