User input/picking from a list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: User input/picking from a list (/thread-32690.html) |
User input/picking from a list - AnunnakiKungFu - Feb-26-2021 I am trying to figure out how to use user input to select items from a list and display how much the item is. This is what I have so far. # Make a program with user input that shows what items on the grocery list cost what: apples = 1.99 bananas = 2.99 oranges = 3.99 item_pull = input("What item would you like to see the price of?: ") RE: User input/picking from a list - buran - Feb-26-2021 there is no list whatsoever in your code. use a data structure like dict . read https://nedbatchelder.com/blog/201112/keep_data_out_of_your_variable_names.html RE: User input/picking from a list - BashBedlam - Feb-27-2021 Like buran indicated, python dictionaries make things like this incredibly easy. items = { 'apples': 1.99, 'bananas': 299, 'oranges': 399 } item_pull = input ('What item would you like to see the price of? : ') if item_pull in items : print (f'The price of {item_pull} is ${items [item_pull]}.') |