-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcensus.py
More file actions
29 lines (23 loc) · 873 Bytes
/
Copy pathcensus.py
File metadata and controls
29 lines (23 loc) · 873 Bytes
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
class Person:
def __init__(self, name, age, favorite_foods):
self.name = name
self.age = age
self.favorite_foods = favorite_foods
def birth_year(self):
return 2000 - self.age
def __str__(self):
return "Name: {} Age: {} Favorite food: {}".format(
self.name, self.age, self.favorite_foods[0])
people = [Person("Bill", 11, ["hotdogs", "jawbreakers"])
, Person("Will", 11, ["broccoli"])
, Person("Jill", 12, ["chunky puffs", "jawbreakers"])]
age_sum = 0
year_sum = 0
for person in people:
age_sum = age_sum + person.age
year_sum = year_sum + person.birth_year()
print("The average age is: " + str(age_sum / len(people)))
print("The average birth year is: " + str(int(year_sum) / len(people)))
print("The people polled in this census were:")
for person in people:
print(person)