Last answered:

03 Oct 2022

Posted on:

01 Oct 2022

0

Question 1- is it another way to solve the problem?

capitals={'France':'Paris', 'Spain':'Madrid', 'United Kingdom':'London', 'India': 'New Delhi', 'United States':'Washington DC', 'Italy': 'Rome', 'Denmark':'Copenhagen', 'Germany':'Berlin', 'Greece':'Athens', 'Bulgaria':'Sofia'}
user_input= input('Put a country to check: ')
while user_input!= 'exist':
    if user_input in capitals:
        print(capitals[user_input])
    else:
        print('it\'s not in the dictionary)
    user_input=input('put another a country to check: ')

1 answers ( 0 marked as helpful)
Instructor
Posted on:

03 Oct 2022

1

Hey Tuyen,

Thank you for engaging with the Python Programmer Bootcamp course!

What you have posted is a perfectly working solution. I would only make the following adjustment: the user_input variable inside the while-loop could instead read
Put another country to check or type 'exit':
Otherwise, the user wouldn't know how to exit the program :)

Enjoy the rest of the course!

Kind regards,
365 Hristina

Submit an answer