0
dictionary
def nameID(): for i in range (5): name =input( "name : ") id = int(input("Id : ")) nameid = {} nameid[name] = id nameID() Hello I want to add a key value for this dict with for loop but it doesnt work whats problem?
2 Respostas
+ 4
nameid = {}
move this outside the loop
You also don't print or return anything from the function, so there isn't any output.
+ 1
it works thanks