python - When trying to run a method, get 'NoneType is not callable' -


i'm new programming please gentle. on past few days or i've messed around code trying work, , i've done lot of research (well, lot me guess) in , out of stackoverflow, won't repeating question billionth time. also, apologies poor , difficult read code. i'm doing teach myself using classes , methods.

the problem somewhere between return self.rm3 in rm1 method, , code rm3 itself.

my code this:

from sys import exit random import randint  def death():     print 'you "dead", guess.'     exit(0)  def inp(prompt='what do? '):     to_return = raw_input(prompt).lower()     if to_return == 'q' or to_return == 'quit':         print "bye now~"         exit(0)     else:         return to_return  class rooms(object):     def __init__(self):         current_room = self.rm1         self.items = []         while true:             current_room = current_room()     def rm1(self):         print "=== in room 1 ==="         print "you in dark room."         print "obvious exits east , south."         while true:             choice = inp()             if choice == "east":                 return self.rm2             elif choice == "south":                 return self.rm3             elif choice == "look":                 return self.rm1     def rm2(self):         print "=== in room 2 ==="         if "haircomb" not in self.items:             print "there high-tech looking keypad on southernly wall,"             print "next door."             print "upon closer inspection there not numbers, three"             print "letters on keypad: a, m, , z."             print "do try guess code?"         print "obvious exits west , south."         while true:             choice = inp()             if "guess code" in choice , "haircomb" not in self.items:                 return self.rm2guess             elif choice == "west":                 return self.rm1             elif choice == "south" , "haircomb" not in self.items:                 print "the door firmly locked."             elif choice == "south" , "haircomb" in self.items:                 return self.rm4             elif choice == "look":                 return self.rm2     def rm2guess(self):         correct_answer = randint(1,3)         guesses_left = 2         print "you approach keypad."         while true:             guess = inp("which key press? ").lower()             if guess == "a" or guess == "m" or guess == "z":                 if guess == "a":                     guess = 1                 elif guess == "m":                     guess = 2                 elif guess == "z":                     guess = 3                 if guess == correct_answer:                     print "the machine whirrs , beeps."                     print "the southernly door seems open now."                     print "suddenly, haircomb falls bottom of "                     print "keypad. take it."                     self.items.append("haircomb")                     return self.rm2                 elif guess != correct_answer , guesses_left > 0:                     print "the machine whirrs , clicks %s times." \                                                         % guesses_left                     guesses_left -= 1                 elif guess != correct_answer , guesses_left == 0:                     print "an alarm goes off , police pick up."                     print "you put on death row, because live under a"                     print "horrible dictatorship."                     death()             else:                 print "that ain't no key on pad, yo."     def rm3(self):         def __init__(self):             if "coin" not in self.items:                 print "you come room. man stands @ doorway."                 print "he tells in order pass door, need to"                 print "guess hand holds coin."                 print "do try guess?"             print "obvious exits east , north."             while true:                 choice = inp()                 if "guess" in choice:                     return self.rm3guess                 elif choice == "north":                     return self.rm1     def rm4(self):         def __init__(self):             print "room 4"             raw_input             return self.rm4     def rm5(self):         pass     def rm6(self):         pass  game = rooms() 

output when running , typing in 'south' is:

=== in room 1 === in dark room. obvious exits east , south. do? south traceback (most recent call last):   file "ta.py", line 141, in <module>     game = rooms()   file "ta.py", line 44, in __init__     current_room = current_room() typeerror: 'nonetype' object not callable  shell returned 1 

i'm not sure how such error happen? why method rm3 none type when it's defined in class?

why adding __init__ function inside functions? constructor added in class. removing solves problem. able enter south , go further.

from sys import exit random import randint  def death():     print 'you "dead", guess.'     exit(0)  def inp(prompt='what do? '):     to_return = raw_input(prompt).lower()     if to_return == 'q' or to_return == 'quit':         print "bye now~"         exit(0)     else:         return to_return  class rooms(object):     def __init__(self):         current_room = self.rm1         self.items = []         while true:             current_room = current_room()     def rm1(self):         print "=== in room 1 ==="         print "you in dark room."         print "obvious exits east , south."         while true:             choice = inp()             if choice == "east":                 return self.rm2             elif choice == "south":                 return self.rm3             elif choice == "look":                 return self.rm1     def rm2(self):         print "=== in room 2 ==="         if "haircomb" not in self.items:             print "there high-tech looking keypad on southernly wall,"             print "next door."             print "upon closer inspection there not numbers, three"             print "letters on keypad: a, m, , z."             print "do try guess code?"         print "obvious exits west , south."         while true:             choice = inp()             if "guess code" in choice , "haircomb" not in self.items:                 return self.rm2guess             elif choice == "west":                 return self.rm1             elif choice == "south" , "haircomb" not in self.items:                 print "the door firmly locked."             elif choice == "south" , "haircomb" in self.items:                 return self.rm4             elif choice == "look":                 return self.rm2     def rm2guess(self):         correct_answer = randint(1,3)         guesses_left = 2         print "you approach keypad."         while true:             guess = inp("which key press? ").lower()             if guess == "a" or guess == "m" or guess == "z":                 if guess == "a":                     guess = 1                 elif guess == "m":                     guess = 2                 elif guess == "z":                     guess = 3                 if guess == correct_answer:                     print "the machine whirrs , beeps."                     print "the southernly door seems open now."                     print "suddenly, haircomb falls bottom of "                     print "keypad. take it."                     self.items.append("haircomb")                     return self.rm2                 elif guess != correct_answer , guesses_left > 0:                     print "the machine whirrs , clicks %s times." \                                                         % guesses_left                     guesses_left -= 1                 elif guess != correct_answer , guesses_left == 0:                     print "an alarm goes off , police pick up."                     print "you put on death row, because live under a"                     print "horrible dictatorship."                     death()             else:                 print "that ain't no key on pad, yo."     def rm3(self):         if "coin" not in self.items:             print "you come room. man stands @ doorway."             print "he tells in order pass door, need to"             print "guess hand holds coin."             print "do try guess?"         print "obvious exits east , north."         while true:             choice = inp()             if "guess" in choice:                 return self.rm3guess             elif choice == "north":                 return self.rm1     def rm4(self):         print "room 4"         raw_input         return self.rm4     def rm5(self):         pass     def rm6(self):         pass  game = rooms() 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -