Explain classes on my site.
Quick class run down.
self refer to class object. Class object must be created.
If your function effects class only. Then make it part of the class.
Example
Couple of other tips.
Try avoid keyword names.
Try to follow style guide.
Quick class run down.
self refer to class object. Class object must be created.
player = Player(...) # create a new player object player2 = Player(...) # create another new player objectplayer and player2 are to different objects.
If your function effects class only. Then make it part of the class.
Example
#Class class Player(): def __init__(self, name="", strength=0, constitution=0, intelligence=0, health=0, mana=0, attack=0): self.name = name self.str = strength self.con = constitution self.int = intelligence self.hp = health self.mp = mana self.attack = attack # Allows to print and represent it self in other areas. def __repr__(self): return str(vars(self)) # Method def creation(self): name = input('What do they call you?: ') self.name = name print('Welcome {}, Make your Character!'.format(self.name)) points = 10 for points_left in range(points): print('1: Add point in Strength') print('2: Add point in Constitution') print('3: Add point in Intelligence') retries = 0 while True: choice = input('Add 1 to a skill: ') choice = choice.strip() if choice in ['1', '2', '3']: break print('Try Again !') retries += 1 if retries > 3: print('You having to much trouble. Seek assistent.\nGood Bye') exit() print('You have {} points left!'.format(points - points_left - 1)) if choice == '1': self.str += 1 print("strength:", self.str) elif choice == '2': self.con += 1 print("constitution:", self.con) elif choice == '3': self.int += 1 print("intelligence:", self.int) def main(): player = Player() player.creation() print(player) main()
Couple of other tips.
Try avoid keyword names.
Try to follow style guide.
99 percent of computer problems exists between chair and keyboard.