Python Forum
Printing class results returns 'none'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing class results returns 'none'
#1
Hi, I've recently got into learning the Python language using Python 3.7.
I'm using the base of a text rpg to sort of learn the ropes of Python since it's something that I am interested in. I designated the class, and have it set to print the 'Stats' class so that I can change the values later on with user input. The console is printing the stats like I want, but with an added 'None' after the numbers. Can someone explain why this is happening, and how I should fix it? If you're just going to post code without an explanation please don't... I'm trying to learn, after all :)

Code:
class Stats:
    
    def __init__(self, strength=0, dexterity=0, wisdom=0, intelligence=0):
        self.strength = strength
        self.dexterity = dexterity
        self.wisdom = wisdom
        self.intelligence = intelligence
        
    def getStats(self):
        print(self.strength, self.dexterity, self.wisdom, self.intelligence)
        
    def statinput(self, value1, value2, value3, value4):
        self.value1 = strength_input
        self.value2 = dexterity_input
        self.value3 = wisdom_input
        self.value4 = intelligence_input
        if strength_input:
            self.strength = self.strength + value1
        if dexterity_input:
            self.dexterity = self.dexterity + value2
        if wisdom_input:
            self.wisdom = self.wisdom + value3
        if intelligence_input:
            self.intelligence = self.intelligence + value4
            
player = Stats(1, 1, 1, 1)
print(player.getStats())

strength_input = int(input('Enter a value for strength.'))
dexterity_input = int(input('Enter a value for dexterity.'))
wisdom_input = int(input('Enter a value for wisdom.'))
intelligence_input = int(input('Enter a value for intelligence.'))

player_stat_choice = player.statinput(strength_input, dexterity_input,
                            wisdom_input, intelligence_input,)

print(player.getStats())
All of the above code functions, but is printing the following to console:
1 1 1 1
None
Enter a value for strength.2
Enter a value for dexterity.2
Enter a value for wisdom.2
Enter a value for intelligence.2
3 3 3 3
None
I'm not sure if the 'None' portion is going to affect anything later on down the road after I've expanded this bit, so I'd like to handle it now :) Thanks ahead for your time.
Reply


Messages In This Thread
Printing class results returns 'none' - by Lawr3y - Aug-16-2019, 12:22 AM

Forum Jump:

User Panel Messages

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