This code works so that when I give an input word
, if it matches with a term
stored in a dictionary, it prints the definition of asked term
. I am trying to add a feature where if I give an input
that is not a term in the dictionary, I do a little check to see if any part of the word
, is stored as term
in the dictionary.
word = input("Enter a programming term you want to know about: ")
terms = {
"tuple" : "Variables are containers for storing data (storing data values)."
}
def return_definition(word):
output = ""
for term, value in terms:
if word == term :
output += terms.get(key)
elif term in word:
output += terms.get(value)
return output
print(return_definition(word))
The elif
conditional tests if the user inputs something not in the dictionary e.g. "tuples". I would like to return the definition of tuple to them, so I check term in word
, to make it so that program returns the definition for tuple. However, instead of returning the definition, the program causes this error
Traceback (most recent call last):
File "e:\Code\Python Code\Exercises\dictionary.py", line 48, in <module>
print(returnDefinition(word))
File "e:\Code\Python Code\Exercises\dictionary.py", line 41, in returnDefinition
for term, value in terms:
ValueError: too many values to unpack (expected 2)