Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modifying Classes
#2
I'm not getting errors. I also want to point out how your code could be shortened down to this rather than using a bunch of if statements.
class Player:
    def __init__(self, stats, Name = ''):
        self.Name = Name
        self.Strength = stats['Strength']
        self.Constitution = stats['Constitution']
        self.Intelligence = stats['Intelligence']
 
 
def character_creation(Player):
    statsDict = {'Strength' : 0, 'Constitution' : 0, 'Intelligence' : 0} ##Store skill pts
    PointDict = {'1' : 'Strength', '2' : 'Constitution', '3' : 'Intelligence'} #Use number to determine the skill
    points_left = 10
    while points_left > 0:
        print('1: Add point in Strength')
        print('2: Add point in Constitution')
        print('3: Add point in Intelligence')
        choice = input('Add 1 to a skill: ')
        while choice not in PointDict: #Make sure they're answer is valid
            choice = input('Add 1 to a skill: ')
        
        statsDict[PointDict[choice]] += 1 #Add a skill point
        points_left -= 1 #Take away a pt
        
        print('%s: %s' %(PointDict[choice], statsDict[PointDict[choice]]))
        print('You have %s points left!' %points_left)
    return Player(stats=statsDict) #After the while loop return a player. Give the player the whole stats dictionary is easier
 
character_creation(Player)
Reply


Messages In This Thread
Modifying Classes - by Tridium - Aug-02-2019, 11:44 PM
RE: Modifying Classes - by SheeppOSU - Aug-02-2019, 11:59 PM
RE: Modifying Classes - by ndc85430 - Aug-03-2019, 06:06 AM
RE: Modifying Classes - by Windspar - Aug-03-2019, 03:42 PM
RE: Modifying Classes - by Tridium - Aug-03-2019, 05:41 PM

Forum Jump:

User Panel Messages

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