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)
566 Understanding How to Configure Google API Key
563 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
589 GDB gets version error when attempting to debug with the Presense SDK (IDE)
853 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.