Saturday, 7 September 2013

Python 3 input and if statement

Python 3 input and if statement

I am having some trouble with an input question that is supposed to allow
the player to choose one of 5 starting races. I used the following code.
def racechoice():
players.race = input('After you get a chance to think, you choose to
be...') #Here race is chosen
if players.race == "dwarf" or "Dwarf": #Race starting stats
players.race = "Dwarf"
players.level = 1
players.strength = 12
players.agility = 6
players.inteligence = 8
players.vitality = 14
elif players.race == "Orc" or "orc":
players.race = "Orc"
players.level = 1
players.strength = 14
players.agility = 10
players.inteligence = 4
players.vitality = 12
elif players.race == "elf" or "Elf":
players.level = 1
players.race = "Elf"
players.strength = 8
players.agility = 13
players.inteligence = 12
players.vitality = 7
elif players.race == "Human" or "human":
players.level = 1
players.race = "Human"
players.strength = 10
players.agility = 10
players.inteligence = 10
players.vitality = 10
elif players.race == "gnome" or "Gnome":
players.race = "Gnome"
players.strength = 5
players.agility = 11
players.intelligence = 17
players.vitality = 7
When called to display the player's stats:
def stats():
print(players.name)
print(players.race)
print("Level: "+ str(players.level) +" Strength: "+ str(players.strength)
+" Agility: " + str(players.agility) +" Inteligence: "+
str(players.inteligence) +" Vitality: "+ str(players.vitality))
It comes back as Dwarf with Dwarf stats no matter what the player chooses.
I'm new-ish to Python and was wondering, did I not use the if/elif
statement(s) correctly?

No comments:

Post a Comment