Create a list containing country name and the population. Get a country name from user, display the population in that country. Display the countries whose population is less than one lakh. Display also the countries with minimum and maximum population.
#you can add the name of countries and their population
cp = ["USA 333844797", "Pakistan 216565318", "India 1399902189", ]
user_input = input("Enter country name: ")
for i in cp:
if user_input == i.split(" ")[0]:
print(f"The population of {user_input} is: ")
print("__________________")
print("__________________")
print("Countries with population less than 100000")
min_pop = 0
max_pop = 0
ind_min = 0
ind_max = 0
for j, i in enumerate(cp):
if int(i.split()[1]) < 100000:
print(i.split()[0])
if int(i.split()[1]) > max_pop:
max_pop = int(i.split()[1])
ind_max = j
if int(i.split()[1]) < min_pop:
min_pop = int(i.split()[1])
ind_min = j
print("__________________")
print("__________________")
print(f"{cp[ind_max]} has the max population")
print("__________________")
print("__________________")
print(f"{cp[ind_min]} has the min population")
Comments
Leave a comment