The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

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

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

1
Vote
0
Answer

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 ……

No answers so far.