[Tutor] Another question, dictionaries
Roger Lea Scherer
rls4jc at gmail.com
Fri Mar 2 16:05:42 EST 2018
I'm trying to finish chapter 5 in my book and it has to do with
dictionaries and creating simple games. We need a pool of points and the
ability to exchange point between the pool and each of the, what I call,
attributes of Strength, Health, Wisdom, and Dexterity. I got only to the
first option and I'm stuck on how to get the points to change
"permanently". The program will run well for option 1 (I haven't got to the
rest of the options), but the next time I run the program it goes back to
the original configuration. Did I do everything right, but I just need to
write to a file, and that's what the problem is? or what?
I've reread the chapter, I've gone on stackoverflow and thegeekstuff.com,
I've thought about it for at least a day and I just can't figure out what
the problem is. Please help?
# Character creator program for role playing
pool = 30
attributes = {"Strength": 0, "Health": 0, "Wisdom": 0, "Dexterity": 0}
print("You have", pool, "points")
print("""
You can apply them to your Strength, Health, Wisdom, or Dexterity.
Press:
0 to Quit
1 to apply points to Strength
2 to apply points to Health
3 to apply points to Wisdom
4 to apply points to Dexterity
5 to apply points from Strength to your pool
6 to apply points from Health to your pool
7 to apply points from Wisdom to your pool
8 to apply points from Dexterity to your pool
""")
choice = input("Choice: ")
print(attributes.get("Strength"))
if choice == "0":
print("Good-bye.")
input("\n\nPress enter to exit.")
elif choice == "1":
strengthChoice = input("How many points would you like to transfer from
pool to Strength?: ")
print(strengthChoice)
attributes["Strength"] += int(strengthChoice)
print(attributes.get("Strength"))
pool -= int(strengthChoice)
print(pool)
More information about the Tutor
mailing list