Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using math on 2 dictionary values together

Here is my code

AZcounties = {

            "Maricopa" : "4,496,588",
            "Pima" : "1,052,030",
            "Pinal" : "449,557",
            "Yavapai" : "242,253",
            "Mohave" : "217,692",
            "Yuma" : "206,990",
            "Coconino" : "145,052",
            "Cochise" : "126,052",
            "Navajo" : "108,147",
            "Apache" : "65,623",
            "Gila" : "53,589",
            "Santa Cruz" : "47,883",
            "Graham" : "39,050",
            "La Paz" : "16,408",
            "Greenlee" : "9,404",
        }
   
 print ("Which Arizona county would you like to see the population of?")
 
 county = input ("Enter county: ")

How would I get the users inputted counties population number into a variable so I can use math like a regular number.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the dict.get,

value = int(AZcounties.get(county).replace(',', ''))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading