I have a system where a list of names are assigned to the value 0 using a dictionary. I would like to cause the value to increment by 1 whenever a user inputs their name.
I've tried using a for loop to iterate through the dictionary, however this only searches the dictionary for the name term by term and does not update the value if the inputted name is not in whatever iteration the loop is at.
i = 0
dic = {"tim":0, "jimbo":0}
while True:
while i < len(dic):
for name, value in dic.items():
try:
userinput = input("Enter name: ").lower()
except(ValueError):
print("Error")
if userinput in name:
dic[name] += 1
i += 1
print(dic)
The print statement at the end does give an updated value, but only if the entered name is within the current iteration of the loop. Ideally I would like the value to update whenever a name within the dictionary is inputted. The console also seems to freeze after four inputs.
Is there a more sensible way of doing this, and specifically doing this for a much larger dictionary with upwards of 100 keys?