-2

I am new to Python and trying very hard to understand this issue here. I asked a previous question, got several answers, tried to use every solution and none of them worked. Please help if you can!

***I am being required to add more text to my question in order to post so please ignore this area. lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum ***

ERROR MESSAGE

Please enter your Super Hero name: 
>PleaseHelpMan
Traceback (most recent call last):
  File "/Users/colinbarclay/Desktop/NEW VERSION of SuperHero Classes..py", line 39, in <module>
    hero = Superhero(superName, power, braun, brains, stamina, wisdom, constitution, dexterity, speed)
TypeError: Superhero() takes no arguments
>>> 

CODE

#Importing Random Module

import random

#create Superhero class

class Superhero():
    #initializing our class and setting its atrributes
    def _init_(self,superName, power, braun, brains, stamina, wisdom, constitution, dexterity, speed):
        self.superName = superName
        self.power = power
        self.braun = braun
        self.brains = brains
        self.stamina = stamina
        self.wisdom = wisdom
        self.constitution = constitution
        self.dexterity = dexterity
        self.speed = speed

print("Please enter your Super Hero name: ")

# assigning a value to superName using the user's input
superName = input('>')

# adding random values to each

power = random.randint(1,20)
braun = random.randint(1,20)
brains = random.randint(1,20)
stamina = random.randint(1,20)
wisdom = random.randint(1,20)
constitution = random.randint(1,20)
dexterity = random.randint(1,20)
speed = random.randint(1,20)


# creating the super hero object
hero = Superhero(superName, power, braun, brains, stamina, wisdom, constitution, dexterity, speed)

# print the result of the created object, including its parameters

print("Your name is %s. " % (hero.superName))
print("Your new stats are: ")
print("")
print("Brains: ", hero.brains)
print("Braun: ", hero.braun)
print("Stamina: ", hero.stamina)
print("Wisdom: ", hero.wisdom)
print("Constitution: ", hero.constitution)
print("Dexterity: ", hero.dexterity)
print("Speed: ", hero.speed)
print("")

1 Answers1

2

_init_ should have two sets of underscores, not one. So, it should be __init__ https://www.w3schools.com/python/python_classes.asp

George
  • 267
  • 2
  • 6