-
Notifications
You must be signed in to change notification settings - Fork 0
/
L12Q5_ListsOfLists.py
48 lines (38 loc) · 1.37 KB
/
L12Q5_ListsOfLists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Define a procedure, total_enrollment,
# that takes as an input a list of elements,
# where each element is a list containing
# three elements: a university name,
# the total number of students enrolled,
# and the annual tuition fees.
# The procedure should return two numbers,
# not a string,
# giving the total number of students
# enrolled at all of the universities
# in the list, and the total tuition fees
# (which is the sum of the number
# of students enrolled times the
# tuition fees for each university).
udacious_univs = [['Udacity',90000,0]]
udacious_univs1 = [['Udacity',90000,10]]
usa_univs = [ ['California Institute of Technology',2175,37704],
['Harvard',19627,39849],
['Massachusetts Institute of Technology',10566,40732],
['Princeton',7802,37000],
['Rice',5879,35551],
['Stanford',19535,40569],
['Yale',11701,40500] ]
def total_enrollment(p):
enrolled = 0
total_fees = 0
for i in p:
enrolled += i[1]
total_fees += i[1]*i[2]
return [enrolled,total_fees]
print total_enrollment(udacious_univs1)
print total_enrollment(udacious_univs)
#>>> (90000,0)
# The L is automatically added by Python to indicate a long
# number. If you are trying the question in an outside
# interpreter you might not see it.
print total_enrollment(usa_univs)
#>>> (77285,3058581079)