Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

if you have a list and the user input one of the keys then output its value

# here is a list of food and its Calories 
list ={
    "Apple": "130",
    "Avocado": "50",
}
# get the key from user and print its value
try:
    item = str(input("Item: "))
    print(list[f"{item}"])
except KeyError:
    pass
 
PREVIOUS NEXT
Tagged: #list #user #input #keys #output
ADD COMMENT
Topic
Name
2+7 =