I am making an English dictionary using for in syntax.
dic = {
'apple' : 'Apple',
'banana' : 'banana',
'orange' : 'orange',
'music' : 'music',
'door' : 'door',
"Bear" : "Bear",
'dog' : 'dog',
'cat' : 'Cat'
}
for i in range(len(dic)):
word = input ('word input:')
if word in dic:
print('meaning: {}'.format(dic[word]))
else:
print('This word is not in the dictionary. Please register the meaning.')
I've done it up to here
You have to add words that don't exist and save them in the dic ㅜ<
What do I do?
python
I added a stop function in the middle, but it worked anyway.
dic = {
'apple' : 'Apple',
'banana' : 'banana',
'orange' : 'orange',
'music' : 'music',
'door' : 'door',
"Bear" : "Bear",
'dog' : 'dog',
'cat' : 'Cat'
}
for i in range(len(dic)):
word = input ('word input:')
if word in dic:
print('meaning: {}'.format(dic[word]))
elif word == 'stop':
break
else:
print('This word is not in the dictionary. Please register the meaning.')
mean = input('Enter meaning :')
dic[word] = mean
When adding dict elements, you can give an update command.
dic = {
'apple' : 'Apple',
'banana' : 'banana',
'orange' : 'orange',
'music' : 'music',
'door' : 'door',
"Bear" : "Bear",
'dog' : 'dog',
'cat' : 'Cat'
}
Please enter word = input(').\nWord : ')
if word in [i for i in dic]:
print('meaning: {}'.format(dic[word]))
# # [i for i in dic] >> ['apple', 'banana', 'orange', 'music', 'door', 'bear', 'dog', 'cat']
else:
print('This word is not in the dictionary. Please register the meaning.')
Please enter the meaning of the word mean = input(').\nMeaning :')
newword = {word:mean}
dic.update(newword)
print(dic)
© 2025 OneMinuteCode. All rights reserved.