Computer Science, asked by lipumaity, 9 months ago

Write a program in python to input names of 'n' countries and their capital and currency, store it in a dictionary and display in tabular form. Also search and display for a particular country. ​

Answers

Answered by SweetyTanuja22
27

Answer:

1-In this program first you will call the dictionary function

2-then you will initialise the counter i as 1

3-ask the no.of entries from user

4-give while condition

5-ask user to enter input(capital,country,currency)

6-store tuple in dictionary

7-increment value of i

8-call keys usinf keys() function

9-print them in tabular for

10-ask user input of country to be searched

11-print the country,capital,currency of asked country

Explanation:

Attachments:
Answered by Equestriadash
70

n = int(input("Enter the number of countries to be be entered: "))

print()

cnt_dict = dict()

for i in range(n):

   x = input("Enter the country name: ")

   y = input("Enter the capital: ")

   z = input("Enter the currency: ")

   print()

   cnt_dict[x] = y, z

print()

print("This is your given dictionary: ")

print("Country", "\t\t", "Capital", "\t\t", "Currency")

for i in cnt_dict:

   print(i, "\t\t\t", cnt_dict[i][0], "\t\t\t", cnt_dict[i][1])

print()

rc = input("Enter the country whose details you'd like view: ")

if rc in cnt_dict:

   print(rc, ":", cnt_dict[rc])

else:

   print("No such country in the given dictionary.")

Similar questions