Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P01 #2

Open
joerez opened this issue Aug 21, 2018 · 1 comment
Open

P01 #2

joerez opened this issue Aug 21, 2018 · 1 comment

Comments

@joerez
Copy link

joerez commented Aug 21, 2018

I got to the: A Note on Scope and Encapsulation section before I got stuck. A big part of it is not being confident that I'm doing this correctly.

Here was my code when I get stuck.

import random

class Ability:
    def __init__(self, name, attack_strength):
        # Initialize starting values
        self.attack_strength = 20 // 8

    def attack(self):
        # return attack value
        self.attack = randint(2, attack_strength)
        return self.attack

    def update_attack(self, attack_strength):
        # update attack value
        self.attack_strength = attack_strength

class Hero:
    def __init__(self, name):
        # Initialize starting values
        self.abilities = list()
        self.name = name

    def add_ability(self, ability):
        # Add ability to abilities list
        self.add_ability = self.abilities.append(ability)

    def attack(self):
        # Run attack() on every ability hero has
        for ability in self.abilities:
            ability.attack

if __name__ == "__main__":
    # If you run this file from the terminal this block is executed.
    hero = Hero("Wonder Woman")
    print(hero.attack())
    ability = Ability("Divine Speed", 300)
    hero.add_ability(ability)
    print(hero.attack())
    new_ability = Ability("Super Human Strength", 800)
    hero.add_ability(new_ability)
    print(hero.attack())

Here is the error I'm getting in my console:

None
None
Traceback (most recent call last):
  File "superheroes.py", line 40, in <module>

    hero.add_ability(new_ability)
TypeError: 'NoneType' object is not callable

I think it would be beneficial for me to see the solutions. I'm not sure if I'm doing this right yet.

I will revisit this tomorrow morning. Perhaps we could work together on it?

@JSitter
Copy link
Contributor

JSitter commented Aug 21, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants