0

I am making a text based game as one of my first projects, and want to print the different categories you can but a skill point in. I made a dictionary with the skill and its function in the game. I want to print both on the screen all together for example:

Health: This increases total health 

That's what I have right now:

while True: 
  print("You will now choose a skill to level up")
  skills = {
    "Health": "This increases total health",
    "Defense": "This increases damage negation",
    "Luck": "This increases all chances",
  }
  for c in skills:
    print(c)
  break

I only know how to get it to print the first part of the dictionary. A solution would be appreciated, but if you could also explain it so I can get a better understanding that would also be great.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
zmoney
  • 11

1 Answers1

0

for c in skills: only iterates over the dictionary's keys.

You need to extract the key and value pairs instead:

while True: 
  print("You will now choose a skill to level up")
  skills = {
    "Health": "This increases total health",
    "Defense": "This increases damage negation",
    "Luck": "This increases all chances",
  }
  for key, value in skills.items():
    print(key+ ": " + value)
  break

This outputs:

You will now choose a skill to level up
Health: This increases total health
Defense: This increases damage negation
Luck: This increases all chances
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Sheldon
  • 4,084
  • 3
  • 20
  • 41
  • 1
    I appreciate it, that cleared a lot up for me. Im very new to programming, and am taking a very trial and error approach to it. This project has me looking up things constantly, but thanks for the help :) – zmoney Mar 15 '22 at 19:20