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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -