I have a list, in the list I would like lists with the first item of the list containing a name and the second containing the dictionary that relates to that name for example:
[['James',{'name':'Thor', 'age':'30', 'race':'human', 'class':'fighter'}],['Tim',{'name':'Sally', 'age':'28', 'race':'half-orc', 'class':'cleric'}]]
Currently the code for my function is:
def add(chars):
thisChar = []
newChar = dict()
print type(newChar)
print type(chars)
name = raw_input("What is your name? ").strip()
thisChar.append(name)
for field in attributes:
userInput = raw_input("What is your " + field + "?")
newChar[field] = userInput
thisChar.append(newChar)
chars.append(thisChar)
return chars
But on the second pass though it throws a type error exception. What have I missed here?
My full code is:
attributes = ["Race", "Class", "Level", "Hit points", "Speed", "Initiative Bonus", "Strength", "Constitution", "Dexterity"
, "Inelegance", "Wisdom", "Charisma", "Armor class", "Fortitude", "Reflex", "Will Power", "Passive Insight", "Passive Perception"]
chars = []
def display(chars):
print chars
return
def add(chars):
thisChar = []
newChar = dict()
name = raw_input("What is your name? ").strip()
thisChar.append(name)
for field in attributes:
userInput = raw_input("What is your " + field + "?")
newChar[field] = userInput
thisChar.append(newChar)
chars.append(thisChar)
return chars
while True:
print "Welcome to the D&D 4th edition Dungeon Master reference"
print "D - Display "
print "A - Add "
print "Q - Quit"
userChoice = raw_input("What would you like to do? ")
userChoice.lower()
if userChoice == "d":
chars = display(chars)
elif userChoice == "a":
chars = add(chars)
else:
print "Bye"
quit()
My full error is:
Traceback (most recent call last):
File "C:/****/Python/charDisplay/AddAndShow.py", line 133, in <module>
chars = add(chars)
File "C:/****/Python/charDisplay/AddAndShow.py", line 120, in add
chars.append(thisChar)
AttributeError: 'NoneType' object has no attribute 'append'