class BankAccount:
    def __init__(self,name,account,balance):
        self.name = name
        self.account = account
        self.balance = balance
    def __str__(self):
        strBalance = str(self.balance)
        msg = 'my name is'+' '+self.name + 'my account is'+' '+self.account +'my balance is' +' '+strBalance
        return msg
        
    def take(self,get):
        self.balance = float(self.balance) - float(get)
        return self.balance

    def put(self,putin):
        self.balance = float(self.balance) + float(putin)
        return self.balance

myAccount = BankAccount('ye','zbao','67000')
myAccount.take(raw_input('how much do you want to take:'))
print 'my balance is:',myAccount.take

键入how much do you want to take:5000
输出为my balance is: <bound method BankAccount.take of <__main__.BankAccount instance at 0x0A1EC9B8>


举报 使用道具
| 回复

共 2 个关于本帖的回复 最后回复于 2016-8-11 17:06

沙发
ippfon 版主 发表于 2016-8-11 10:55:45 | 只看该作者
本帖最后由 ippfon 于 2016-8-11 11:00 编辑

最有一句输出写的有问题,你输出的是 BankAccount.take变量,而你的BankAccount类中没有这个变量
如果要输出BankAccount.take()函数的返回值,你可以先用一个变量接收 myAccount.take(raw_input('how much do you want to take:')) 的返回值,再输出
如:
  1. result = myAccount.take(raw_input('how much do you want to take:'))
  2. print result
复制代码
举报 使用道具
板凳
y2263376780 新手上路 发表于 2016-8-11 17:06:59 | 只看该作者
ippfon 发表于 2016-8-11 10:55
最有一句输出写的有问题,你输出的是 BankAccount.take变量,而你的BankAccount类中没有这个变量
如果要输 ...

完美解决。非常感谢!
举报 使用道具
您需要登录后才可以回帖 登录 | 立即注册

精彩推荐

  • Gephi社会网络分析-马蜂窝游记文本分词并同
  • Gephi社会网络分析-基于马蜂窝游记文本以词
  • 知乎话题文本根据词语间距筛选后生成共词矩
  • 马蜂窝游记文本分词后以词语间距为筛选条件
  • 学习使用apriori算法挖掘关联关系

热门用户

GMT+8, 2024-4-28 01:10