0

I would like to make a user updating the values from a dictionnary in python. I managed to write this code so far which is working :

myDict = {'NAME': '', 'PARENT': '', 'TEACHER': ''}

for k, v in myDict.items():
    v = input(
        'please enter a value for NAME, PARENT and TEACHER : ')
    myDict[k] = v

print(myDict)

The problem is that I would rather prefer to get a prompt for each keys like :

'Please enter value for NAME: '
'Please enter value for PARENT: '
'Please enter value for TEACHER: '

thank you!

Xzi.

ewokx
  • 2,204
  • 3
  • 14
  • 27
Vincent Aury
  • 195
  • 6

1 Answers1

0

Just put k in the prompt.

There's also no need to use items() since you don't care about the old value. Just loop over the keys.

for k in myDict:
    v = input(f'Please enter a value for {k}: ')
    myDict[k] = v
Barmar
  • 741,623
  • 53
  • 500
  • 612