diff --git a/README.md b/README.md index 6d7f0c9..da7a213 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/group.py b/group.py index e2ec347..33a25ad 100644 --- a/group.py +++ b/group.py @@ -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))