//
dic={'Hong Gil-dong':'010-4444-5555','Kim Jungang':'010-9191-8181','Simcheong':'010-3232-5454'}
while True:
user = input ('name>>')
namelist = list(dic.keys())
numberlist = list(dic.values())
if user in namelist:
print(user, dic[user])
else:
if user == 'add':
newname = input ("What is your name?")
newnum = input ("What's the phone number?" ")
dic[newname] = newnum
print(newname, "Phone number added.")
else:
print("Not Found".")
continue
I made this code.
Enter 'Hong Gil-dong' to display the value of the dictionary.
By the way, how can I get it just by searching for "Honggil"?
python
I think we need to compare the namelist
elements with the user
value in a repetitive sentence.
for i in namelist:
if i.find(user) >= 0:
print(numberlist.__getitem__(namelist.index(i)))
If you do this, you can find even one letter overlapping, but if the name overlaps even one letter, you will need to take care of it accordingly. I think you'll be able to study this part a lot.
571 PHP ssh2_scp_send fails to send files as intended
854 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
589 GDB gets version error when attempting to debug with the Presense SDK (IDE)
583 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.