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.
Answers:
You can use the dict.get
,
value = int(AZcounties.get(county).replace(',', ''))
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.
You can use the dict.get
,
value = int(AZcounties.get(county).replace(',', ''))