Using math on 2 dictionary values together

Question:

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.

Asked By: Nint

||

Answers:

You can use the dict.get,

value = int(AZcounties.get(county).replace(',', ''))
Answered By: Rahul K P
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.