Python 蟒蛇说';int';对象不是';不可呼叫
我的课程有一个小项目,我要写一个模拟一个人银行账户的程序。 我不谈了,下面是代码,还有评论Python 蟒蛇说';int';对象不是';不可呼叫,python,python-3.x,Python,Python 3.x,我的课程有一个小项目,我要写一个模拟一个人银行账户的程序。 我不谈了,下面是代码,还有评论 # -*- coding: utf-8 -*- #This program starts by taking in a user input as shown in the While loop.. #the 2 Methods in the class, 1 is for depositing money and the second is for a withdrawal..
# -*- coding: utf-8 -*-
#This program starts by taking in a user input as shown in the While loop..
#the 2 Methods in the class, 1 is for depositing money and the second is for a withdrawal..
class Account:
newBal = 0
post_bal=0
def __init__(self, balance):
self.balance = balance
def deposit(self, deposit):
self.deposit = int(deposit)
#newBal is the variable that takes the new Balance
Account.newBal = self.balance + self.deposit
print("Your Balance is now {}".format(Account.newBal))
return Account.newBal
def withdraw(self, withdraw):
self.withdraw = int(withdraw)
if self.withdraw > Account.newBal:
return "Error, we have a hard time finding that kind of money..."
else:
print("Withdrawal Accepted, have fun with that dough!")
#post_bal is the variable that stores the balance with the withdrawal taken from it
Account.post_bal = Account.newBal - self.withdraw
return("Your Balance is now {}".format(Account.post_bal))
a = Account(balance=0)
while True:
input_1 = input("What would you like to do today? [1] Deposit, [2] Withdraw ")
if int(input_1) == 1:
print(a.deposit(input("How much would you like to deposit? ")))
elif int(input_1) == 2:
print(a.withdraw(input("How much would you like to withdraw? ")))
else:
print(" I'm not too sure I understand what you're saying...")
有了这个,我能够成功地运行一个完整的循环,存款和金额,然后再取款,所有的输出都被返回。然而,一旦我在循环中第二次得到任何一个动作,我就会得到错误调用
TypeError
Traceback (most recent call last)
<ipython-input-4-6a19e620e3d6> in <module>
33 print(a.deposit(input("How much would you like to deposit? ")))
34 elif int(input_1) == 2:
---> 35 print(a.withdraw(input("How much would you like to withdraw? ")))
36 else:
37 print(" I'm not too sure I understand what you're saying...")
TypeError: 'int' object is not callable
TypeError
回溯(最近一次呼叫最后一次)
在里面
33打印(a.存款(输入(“您想存多少?”))
34 elif int(输入_1)==2:
--->35打印(a.提取(输入(“您想提取多少?”))
36.其他:
37打印(“我不太确定我是否理解你所说的……”)
TypeError:“int”对象不可调用
我不确定我做错了什么 您正在将取款更改为
int
def withdraw(self, withdraw):
self.withdraw = int(withdraw)
使用不同的名称,如
def withdraw(self, withdraw):
self.withdraw_value = int(withdraw)
您正在将取款更改为
int
def withdraw(self, withdraw):
self.withdraw = int(withdraw)
使用不同的名称,如
def withdraw(self, withdraw):
self.withdraw_value = int(withdraw)
您正在使用
取款
和存款
两次。一次作为方法名,然后作为实例属性。设置属性时,您将覆盖该方法。@RadheS,请使用前导下划线命名类的所有变量,以避免这样的命名冲突。例如,self.\u draw
您正在使用draw
和deposit
两次。一次作为方法名,然后作为实例属性。设置属性时,您将覆盖该方法。@RadheS,请使用前导下划线命名类的所有变量,以避免这样的命名冲突。例如,self.\u退出
Ohhh好的,我现在看到了。非常感谢你!我会试试看,让你知道哦,好吧,我现在看到了。非常感谢你!我会试试看,然后告诉你