2016-10-19 9 views
-1

サイドカウンタクラスのメソッドのカウンターリスト全体が機能しません。私はキャップのセットにsetcapをし、各カウンタが限界に達しているかどうかを確認するためにキャップをチェックしたいと思います。クロックが時計内で初期化したいと知っているはずです。あなたのコード内の問題のクラス内のクラスインスタンスの初期化

import time 

class counter(): 
    count = 0 
    cap = 0 
    def _init_(self):pass 
    def reset(self): 
     self.count = 0 
    def increment(self): 
     self.count += 1 
    def setcap(self,x): 
     print x 
     self.cap = x 
    def checkcap(self): 
     if self.cap > self.count: 
      return False 
     else: 
      return True 
class clock(): 
    _hr = counter() 
    _min = counter() 
    _sec = counter() 
    def _init_(self): 
     self._hr.setcap(23) 
     self._min.setcap(59) 
     self._sec.setcap(59) 
    def manualreset(self): 
     self._hr.reset() 
     self._min.reset() 
     self_sec.reset() 
    def tick(self): 
     if self._sec.checkcap(): 
      self._sec.reset() 
      self._min.increment() 
      if self._min.checkcap(): 
       self._min.reset() 
       self._hr.increment() 
       if self._hr.checkcap(): 
        self._hr.reset() 
     else: 
      self._sec.increment() 
newClock = clock() 

raw_input("Press enter to start clock") 
while newClock._hr != 24: 
    newClock.tick() 
    print str(newClock._hr.count).zfill(2) + str(newClock._min.count).zfill(2) + str(newClock._sec.count).zfill(2) 

答えて

0

一つは、あなたのinit関数がのinitであるということです。これはあなたの問題

のうちの1つを解決する必要があります

def __init__(self): 
    pass 

を使用してみてください

関連する問題