LMTLabSep09
In my programming class we are trying to make a text-based RPG. We are required to make a dictionary and then use a list in order to have the stats be printed in a certain order (the order being the order in the list). However, I am having trouble with my "for loop", and the stats continue to print within the dictionary, and therefore in a random order each time. Basically I'm asking how can I use myList
to print the stats in the order that I want?
from random import randint
def main():
#user input
name = input("Enter character name: ")
job = input("Enter character's job title: ")
age = eval(input("Enter character's age: "))
bckstry = input("Enter character's backstory: ")
#randomized stats
strength = randint (20, 30)
agility = randint (10, 20)
intel = randint (5, 50)
#character stats w/ formulas
health = strength * 10
mana = intel * 8
damage = agility * 6
#hero dictionary
myHero = {'name':name,
'job':job,
'age':age,
'backstory':bckstry,
'str':strength,
'agi':agility,
'int':intel,
'health':health,
'mana':mana,
'dmg':damage}
print(myHero)
def callMyHero():
myHero = {'name':name,
'job':job,
'age':age,
'backstory':bckstry,
'str':strength,
'agi':agility,
'int':intel,
'health':health,
'mana':mana,
'dmg':damage}
myList = ['name','job','age','backstory','str','agi','int','health','mana','dmg']
for i in range(0,len(myList)):
print(myList[i])
main()
callMyHero()