Answer to Question #281850 in Python for siddharth

Question #281850

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.


1
Expert's answer
2021-12-22T01:10:28-0500
#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")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS