简体   繁体   English

TypeError:object .__ new __()不带参数

[英]TypeError: object.__new__() takes no parameters

I have been working on Python The Hard Way and am getting the above error and have no clue why. 我一直在研究Python The Hard Way并且我得到了上述错误,并且不知道为什么。 I took out most of the filler text that I thought I could. 我拿出了大部分我认为可能的填充文字。 Sorry if it is a little long. 对不起,如果有点长。

from sys import exit
from random import randint

class Game(object):

    def __int__(self, start):
        self.quips = [
             "You died. You kinda suck at this.",
             "Your mom would be proud. If shw were smarter.",
             "Suck a loser.",
             "I have a small puppy that's better at this."
        ]
        self.start = start

    def play(self):
        next_room_name = self.start

        while True:
            print "\n-------"
            room = getattr(self, next_room_name)
            next_room_name = room()

    def death(self):
            print self.quips[randint(0, len(self.quips)-1)]
            exit(1)

    def central_corridor(self):
        print "The Gothons of Planet Percal #25 have invaded your ship and destroyed"


        action = raw_input("> ")

        if action == "shoot!":
            print "Quick on the draw you yank out your blaster and fire it at the Gothon."
            return 'death'

        elif action == "dodge!":

            print "Like a world class boxer you dodge, weave, slip and slide right"
            return 'death'

        elif action == "tell a joke":

            print "Lucky for you they made you learn Gothon insults in the academy."
            return 'laser_weapon_armory'

        else:
            print "DOES NOT COMPUTE!"
            return "central_corridor"

    def laser_weapon_armory(self):
        print "You do a dive roll into the Weapon Armory, crouch and scan the room"
        print "for more Gothons that might be hiding. It's dead quiet, to quiet,"
        print "You stand up and run to the far side of the room and find the"
        print "neutron bomb in its container. There's a keypad lock on the box"
        print "and you need the code to get the bomb out. If you get the code"
        print "get the bomb. The code is 3 digits."
        code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
        guess = raw_input("[keypad]")
        guesses = 0

        while guess != code and guesses < 10:
            print "BZZZZEDDD!"
            guesses += 1
            guess = raw_input("[keypad]> ")

        if guess == code:
            print "The container clicks open and seal breaks, letting gas out."
            print "You grab the neutron bomb and run as fast as you can to the"
            print "bridge where you must place it in the right spot."
            return 'the_bridge'

        else:
            print "The lock buzzes one last time and then you hear a sickening"
            print "melting sound as the mechanism is fused together."
            print "You decide to sit there, and finally the Gothons blow up"
            print "ship from their ship and you die."
            return 'death'

    def the_bridge(self):
        print "You burst onto the Bridge with the netron destruct bomb"


        action = raw_input("> ")

        if action == "throw the bomb":
            print "In a panic you throw the bomb at the group of Gothons"
            return 'death'

        elif action == "slowly place the bomb":
            print "You point your blaster at the bomb under your arm"
            return 'escape_pod'

        else:
            print "DOES NOT COMPUTE!"
            return "the_bridge"

    def escape_pod(self):
        print "You rush through the ship desperately trying to make it to"


        good_pod = randint(1,5)
        guess = raw_input("[pod #]> ")

        if int(guess) != good_pod:
            print "You jump into pod %s and hit the eject button." % guess
            return 'death'

        else:
            print "You jump into pod %s and hit the eject button." % guess
            print "time. You won!"
            exit(0)

a_game = Game("central_corridor")
a_game.play()

You misspelled __init__ : 你拼错了__init__

def __int__(self, start):
        ^ no "i"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM