Python: If (user_input) in dictionary -


having issue checking if user input in dictionary.

basics of program there's shop inventory. items stored in dictionary corresponding values e.g. {'kettle': 3,.....}

then want user write want. if user has entered 'kettle' want remove item shop inventory , put in user inventory.

the main problem right getting if statement together. i'm trying:

user_choice = input('what buy? ') if user_choice in shop_inventory:     print('complete') else:     print('fail') 

how can program print "complete"?

part of question asking if in dictionary, want remove inventory. believe can use 'del'

user_choice = input('what buy? ') if user_choice in shop_inventory:   del shop_inventory[user_choice]   print(shop_inventory)   print('complete') else:   print('fail') 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -