2016-08-10 9 views
-4

このコードを実行すると、のpython 3.xの - "はTypeError:「int型のオブジェクトが呼び出し可能ではありません"

#Silent Auction 

    class Auction: 

     def __init__(self): 
      self.reserve_price = 30 
      self.highest_bid = 0 
      self.highest_bidder = "" 
      self.namelist = [] 
      self.bidlist = [] 

     def reserve_price(self): 
      print("Hello. The reserve price is ${}".format(self.reserve_price)) 

     def new_bidder(self): 
      LOOP = 0 
      while LOOP == 0: 
       name = input("What is your name? 'F' for FINISH ") 
       if name.upper() == "F": 
        LOOP = 1 
       else: 
        bid = int(input("Hello {}. What is your bid? ".format(name))) 
        if bid > self.highest_bid: 
         self.highest_bid = bid 
         self.highest_bidder = name 
         self.namelist.append(name) 
         self.bidlist.append(bid) 

        else: 
         print("Sorry {}. You'll need to make another higher bid.".format(name)) 
         print("Highest bid so far is ${:.2f}".format(self.highest_bid)) 


     def auction_end(self): 
      if self.highest_bid >= self.reserve_price: 
       print("The auction met the reserve price and the highest bidder was {} with ${:.2f}".format(self.highest_bidder, self.highest_bid)) 
      else: 
       print("The auction did not meet the reserve price") 
       n = len(self.namelist) 
       for i in range (0, n): 
        print("{} bid ${:.2f}".format(self.namelist[n], self.bidlist[n])) 

    if __name__ == "__main__": 
     auction1 = Auction() 
     auction1.reserve_price() 
     auction1.new_bidder() 
     auction1.auction_end() 

私は

Traceback (most recent call last): 
    File "F:\Work\Year 13\13DIP\91637 Programming\Silent Auction.py", line 46, in <module> 
    auction1.reserve_price() 
TypeError: 'int' object is not callable 
>>> 
+1

これは無料のデバッグサービスではありません。あなたはコード全体とスタックトレースをダンプするよりももう少し作業をしなければなりません。 –

答えて

1

エラーを受け取るには、あなたの関数に名前を付け、あなたはいけませんインスタンス変数は同じものです。

def print_reserve_price(self): 

変更

def reserve_price(self): 

私はあなたがJavaから来る場合は、このようなことを行うことができ、それが違いを知っている知っているが、Pythonでの関数は、第一級オブジェクトであり、あなたができますそれらを直接参照してください。すなわち:

In [2]: x = lambda i : i * i 
In [3]: x 
Out[3]: <function __main__.<lambda>> 
In [5]: x(2) 
Out[5]: 4 

しかし、私はまた、あなたのinitメソッドでself.reserve_priceを設定する時には、上記に起こることですどの

In [6]: x = 5 

In [7]: x 
Out[7]: 5 

それを上書きすることができます。

+0

これはひどい要求行動で、私はそれを奨励するためにDV'ingです。ごめんなさい。 –

+1

あなたの意見を謝罪する必要はありません。それがコミュニティのことです。私はちょうど質問が正確なエラーメッセージで十分な小さな文脈でエラーを再現するのに十分なコードを持っていて、ユーザーが新しい可能性があると思う傾向があります。私は、何がうまくいかないのか、私の答えでより多くの文脈を提供できると思います。私は自分自身で、目の別のペアがしばしば捉えることができる「ああダフ」の瞬間をたくさん持っています。 –

+0

ああうわー、今私はとても愚かな気がする。私はIn/Outの内容を正確に理解していませんが、私の関数名が悪いということを理解しています。ありがとう! – Icstaz

0

問題は、あなたが__init__方法

チェックこの具体例を

>>> class A: 
     def __init__(self): 
      self.fun = 42 
     def fun(self): 
      print("funny") 

>>> a = A() 
>>> a.fun 
42 
>>> 

であなたのreserve_priceメソッドを上書きすることであるソリューションは、それらのいずれかの名前を変更し、簡単です。

関連する問題