Last answered:

13 Dec 2022

Posted on:

13 Dec 2022

0

does my code qualify as a way to validate the input and solve the Q please tell me

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', 'Ireland': 'Dublin', 'Mexico': 'Mexico City'
            }
country = input("Please enter a country name\n >>")
while not country.replace(' ', '').isalpha():
    country = input("Please enter a country name correctly\n >>")
country = country.title()
if capitals.get(country) != capitals.get('asap'):
    print(f" The capital of {country} is {capitals.get(country)}")
else:    print(f"{country} doesn't exist in our dictionary or you didn't enter it correctly")
1 answers ( 0 marked as helpful)
Instructor
Posted on:

13 Dec 2022

0

Hey Hosam,

Thank you for reaching out!

Your solution looks good and solves the task as expected.

Kind regards,
365 Hristina

Submit an answer