Python Forum

Full Version: User input/picking from a list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?: ")
there is no list whatsoever in your code. use a data structure like dict.

read https://nedbatchelder.com/blog/201112/ke...names.html
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]}.')