I'm having an issue wherein i'm trying to loop through a dictionary to update all the values based on a specific input from a user.
I've posted my code below, basically, the user inputs a number into the different lanes played input boxes, and the function should update the dictionary to contain the values input by the user.
the loop doesn't seem to be going through every key in my dictionary, only returning the first value and then seemingly skipping the rest.
I am only 3 weeks deep into a python tutorial and I'm not really sure what i am doing wrong here.
please see code below :
def lane_input():
lanes_played = {"Top":0, "Middle":0, "Jungle":0, "Support":0, "ADC":0}
top_played = input("insert the number of times top played")
top_played = int(top_played)
mid_played = input("insert the number of times Middle played")
mid_played = int(mid_played)
Jungle_played = input("insert the number of times Jungle played")
Jungle_played = int(Jungle_played)
Support_played = input("insert the number of times Support played")
Support_played = int(Support_played)
ADC_played = input("insert the number of times ADC played")
ADC_played = int(ADC_played)
for p, n in lanes_played.items():
if p == 'Top':
lanes_played[p] = top_played
if p == 'Middle':
lanes_played[p] = mid_played
if p == 'Jungle':
lanes_played[p] = Jungle_played
if p == 'Support':
lanes_played[p] = Support_played
if p == 'ADC':
lanes_played[p] = ADC_played
return(lanes_played)
print(lanes_played)
print(lanes_played[p])
print(lanes_played[n])
enter code here`enter code here`total = lane_input()
enter code here`print(total)
Code output below :
insert the number of times top played1
insert the number of times Middle played2
insert the number of times Jungle played3
insert the number of times Support played4
insert the number of times ADC played5
{'Top': 1, 'Middle': 0, 'Jungle': 0, 'Support': 0, 'ADC': 0}