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:
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 NoneI'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.