Hello everyone I am struggling on this country capital problem where the user inputs a country and the country and capital are suppose to be the output. Also even if the user enters Sp for spain, all occurrences of that word are suppose to be outputted. So far I am able to only output the value, such as if the user enters spain, Madrid pops up or if Japan is entered, Tokyo is outputted. Any help would be appreciated. Here is a link to the file https://drive.google.com/folderview?...2s&usp=sharing.
Im looking for tips in the right direction and not the answer thank you.
Im looking for tips in the right direction and not the answer thank you.
Code:
print()
print('Hello,this program is to match countries to their capitals'.title())
input_file=open('Country-Capital.csv','r')
country_capital=dict()
for line in input_file:
line=line.split(',')
countries=line[0]
capitals=str(line[1].strip('\n'))
Capitals=capitals.strip(';')
if countries in country_capital:
country_capital[countries].append(Capitals)
else:
country_capital[countries]=[Capitals]
user_input=''
print('Enter -1 to exit to see all Countries and Capitals')
print()
while user_input != '-1':
user_input=input('enter a country to get its capital: ').title()
print('You Entered: ',user_input)
if user_input in country_capital:
print('Answer: ',country_capital[user_input])
print()
print('Enter -1 to exit and to all Countries and Capitals')
print()
else:
print('GAME OVER')
print(' Here are the Countries and Capitals:')
print()
for key,value in country_capital.items():
print('Country: ',key)
print('Capital: ',value)
print(' Here are the Countries and Capitals:')
input_file.close()
and this is my output:
enter a country to get its capital: Spain
You Entered: Spain
Answer: ['Madrid']
Enter -1 to exit and to all Countries and Capitals
enter a country to get its capital: