Skip to content

Instantly share code, notes, and snippets.

  • Select an option

  • Save LizaPiya/2319cd14017c2385b268ab735396788e to your computer and use it in GitHub Desktop.

Select an option

Save LizaPiya/2319cd14017c2385b268ab735396788e to your computer and use it in GitHub Desktop.
Accumulating Results From a Dictionary
## The dictionary travel contains the number of countries within each continent that Jackie has traveled to. Find the total number of countries that Jackie has been to, and save this number to the variable name total. Do not hard code this!
travel = {"North America": 2, "Europe": 8, "South America": 3, "Asia": 4, "Africa":1, "Antarctica": 0, "Australia": 1}
total=0
for i in travel:
total=total+travel[i]
## 2. schedule is a dictionary where a class name is a key and its value is how many credits it was worth. Go through and accumulate the total number of credits that have been earned so far and assign that to the variable total_credits. Do not hardcode.
schedule = {"UARTS 150": 3, "SPANISH 103": 4, "ENGLISH 125": 4, "SI 110": 4, "ENS 356": 2, "WOMENSTD 240": 4, "SI 106": 4, "BIO 118": 3, "SPANISH 231": 4, "PSYCH 111": 4, "LING 111": 3, "SPANISH 232": 4, "STATS 250": 4, "SI 206": 4, "COGSCI 200": 4, "AMCULT 202": 4, "ANTHRO 101": 4}
total_credits=0
for i in schedule:
total_credits=total_credits+schedule[i]
@Ivan6240
Copy link

travel = {"North America": 2, "Europe": 8, "South America": 3, "Asia": 4, "Africa": 1, "Antarctica": 0, "Australia": 1}
total = (sum(travel.values()))
print(total)

Easy way:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment