So, I'm trying to create a RPG just for fun. But, while creating the classes, I noticed that I couldn't choose my class. Everytime I choose a class, I always get the final print. How do I fix this?
while (True):
print("Select your class\n")
print("\nKnight\nArcher\nTank\nRogue\n\n")
classe = input("")
if((classe.strip()).lower() == "Knight"):
forca = 10
defe = 4
hp = 8
agi = 2
inte = 2
break
elif((classe.lower()) == "Archer"):
forca = 6
defe = 6
hp = 6
inte = 8
agi = 7
break
elif((classe.strip()).lower() == "Tank"):
forca = 5
defe = 8
hp = 10
inte = 3
break
elif((class.strip()).lower() == "Rogue"):
strenght += 6
def = 5
hp = 5
inte = 6
agi = 10
break
else:
print("You need to choose one.")
You are using .lower()
then comparing it to words with capital letters ( Tank
). So it will never match. Try this:
while (True):
print("Select your class\n")
print("\nKnight\nArcher\nTank\nRogue\n\n")
classe = input("")
if((classe.strip()).lower() == "knight"):
forca = 10
defe = 4
hp = 8
agi = 2
inte = 2
break
elif((classe.lower()) == "archer"):
forca = 6
defe = 6
hp = 6
inte = 8
agi = 7
break
elif((classe.strip()).lower() == "tank"):
forca = 5
defe = 8
hp = 10
inte = 3
break
# class is a keyword, use classe
elif((classe.strip()).lower() == "rogue"):
# Does this need to be an equals?
strenght = 6
# Def is a keyword, use defe
defe = 5
hp = 5
inte = 6
agi = 10
break
else:
print("You need to choose one.")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.