[Solved] Code a small Python dictionary


Read user input. Repeat for that many number of times – get items from dictionary using get attribute which handles KeyError itself:

dic = {'Hello': 'Salam', 'Goodbye': 'Khodafez', 'Say': 'Goftan', 'We': 'Ma', 'You': 'Shoma'}

n = int(input())
for _ in range(n):
    print(dic.get(input(), 'Wrong Input'))

EDIT:

dic = {'Hello': 'Salam', 'Goodbye': 'Khodafez', 'Say': 'Goftan', 'We': 'Ma', 'You': 'Shoma'}

n = int(input())
for _ in range(n):
    usrinp = input()
    print(dic.get(usrinp, usrinp))

4

solved Code a small Python dictionary