Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Create an example instance, in an editor or a notebook, of a structure for this
- Jill is 26, a biologist and she is Zalika's friend and John's partner.
- Zalika is 28, an artist, and Jill's friend
- John is 27, a writer, and Jill's partner.
- Nash is 34, a chef, John's cousin and Zalika's landlord.
- Nash is 34, a writer, John's cousin and Zalika's landlord.

Some things you may wish to consider in your model:
- Does it allow people who have no job?
Expand Down
63 changes: 60 additions & 3 deletions group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
"""An example of how to represent a group of acquaintances in Python."""
group = {
"Jill": {
"age": 26,
"job": "biologist",
"relations": {
"Zalika": "friend",
"John": "partner"
}
},
"Zalika": {
"age": 28,
"job": "artist",
"relations": {
"Jill": "friend"
}
},
"John": {
"age": 27,
"job": "writer",
"relations": {
"Jill": "partner"
}
},
"Nash": {
"age": 34,
"job": "chef",
"relations": {
"John": "cousin",
"Zalika": "landlord"
}
}
}
#the maximum age of people in the group
ages = []
for i in group:
age = group[i]['age']
ages.append(age)
print("the maximum age of people in the group:", max(ages))

# Your code to go here...
#the average (mean) number of relations among members of the group
rel_nums = 0
for i in group:
rel_num = len(group[i]['relations'])
rel_nums +=rel_num
ave_num = rel_nums / len(group)
print("the average (mean) number of relations among members of the group:", ave_num)

my_group =
#the maximum age of people in the group that have at least one relation
ages = []
for i in group:
if len(group[i]['relations']) >= 1:
age = group[i]['age']
ages.append(age)
print("the maximum age of people in the group that have at least one relation", max(ages))

#the maximum age of people in the group that have at least one friend
ages = []
for i in group:
if 'friend' in group[i]['relations'].values():
age = group[i]['age']
ages.append(age)
print("the maximum age of people in the group that have at least one friend", max(ages))