Im looking for tips in the right direction and not the answer thank you.
Expand|Select|Wrap|Line Numbers
- 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: