Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError?
#1
class player:
    def __init__(self, name, health):
        self.name = name
        self.health = health

    def player_is_attacked(self, dmg_taken):
        return self.health - dmg_taken

    def player_is_healed(self, healing_recieved):
        pass

def beginning():
    player_name = input("What is your name? ")
    main_player = (player_name, 100)
    user_input = input("""
    
    1. Player is attacked
    2. Player is healed
    3. Test your luck
    
                        """)

    if user_input == "1":
        print(main_player.player_is_attacked(20))

beginning()
So I'm trying to learn how to use classes. I want to print out the value of 80 when the player takes 20 damage. Any help or tips is highly appreciated!
Reply


Messages In This Thread
AttributeError? - by ghost0fkarma - Feb-13-2019, 12:50 AM
RE: AttributeError? - by Larz60+ - Feb-13-2019, 01:04 AM
RE: AttributeError? - by ghost0fkarma - Feb-13-2019, 02:02 AM
RE: AttributeError? - by stullis - Feb-13-2019, 02:11 AM
RE: AttributeError? - by ghost0fkarma - Feb-13-2019, 02:23 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020