Last answered:

21 Oct 2020

Posted on:

07 Jun 2020

1

while working with while loop in python, my code is not taking account double letter string like united states or united kingdom

in mentioned below code's output for string united states and united kingdom:

the out put is : "this country is not in the dictionary".

the output should be its capital value.

Code:

capital = {'France':'paris','spain':'madrid','italy':'rome', 'united states':'washington DC', 'united kingdom':'london'}

user_input = input("Which country would you like to check?>>> ")

user_input = user_input.lower()
while ('united kingdom' not in user_input and not user_input.isalpha()):
if user_input == 'united states':
break
print(" please enter string type only.")
user_input = input("which country would you like to check?>>> ")
user_input = user_input.title()
if user_input in capital:
print(f'the capital of {user_input} is {capital[user_input]}.')
else:
print("this country is not in the dictionary. ")

1: I do not know where is an error?

2: I could not understand this logical statment:

"while 'united kingdom' not in user_input and ......

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

21 Oct 2020

0
Hi Sumeera,  thanks for reaching out! Could you please provide a screenshot of your code along with the error or printerror message you're receiving? Thanks in advance.    Best,  The 365 Team

Submit an answer