I am trying to figure out a way to manipulate one dictionary based on the input of a second dictionary. I am working on an exercise that simulates a vending machine. Based on the code below, my intent is to update the coin_stock dictionary based on the one of the options picked from the coin dictionary. For example if 'n' is chosen in menu_str, this means I have deposited a nickle. This would mean my coin_stock['nickles'] should be updated from 25 to 26. I am trying to generalize the code to update coin_stock when any of the coin options are entered in menu_str. I am pretty new to python. I have tried different things, but the code below is as close as I could get.
coin_stock = {'nickles':25, 'dimes':25, 'quarters':25, 'ones':0, 'fives':0}
coin = { 'n': 5, 'd': 10, 'q': 25, 'o': 100, 'f': 500}
while True:
menu_str = input("Indicate your deposit:")
if menu_str in coin:
if coin[menu_str] == 'n':
coin_stock['nickles'] += 1
if coin[menu_str] == 'd':
coin[menu_str] = coin_stock['dimes']
coin[menu_str] += 1
if coin[menu_str] == 'q':
coin[menu_str] = coin_stock['quarters']
coin[menu_str] += 1
if coin[menu_str] == 'o':
coin[menu_str] = coin_stock['ones']
coin[menu_str] += 1
if coin[menu_str] == 'f':
coin[menu_str] = coin_stock['fives']
coin[menu_str] += 1
coin_stock['nickles']+= 1
print(coin_stock['nickles'])