Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary data from group - RongruChen #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
61 changes: 60 additions & 1 deletion group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,64 @@
"""An example of how to represent a group of acquaintances in Python."""


# Your code to go here...
my_group = {"Jill": {"Age": 26,
"Job": "biologist",
"Relationship": {"Zalika": "friend",
"John": "partner"}},

"Zalika": {"Age": 28,
"Job": "artist",
"Relationship": {"Jill": "friend"}},

"John": {"Age": 28,
"Job": "writer",
"Relationship": {"Jill": "partner"}},

"Nash": {"Age": 34,
"Job": "chef",
"Relationship": {"John": "cousin",
"Zalika": "landlord"}}}

#forget(person1, person2) which removes the connection between two people in the group
#add_person(name, age, job, relations) which adds a new person with the given characteristics to the group
#average_age() which calculates the mean age for the group

def forget(person1, person2):
for name, info in my_group.items():
RelationDic = info["Relationship"]
if name == person1:
RelationDic.pop(person2, None)
if name == person2:
RelationDic.pop(person1, None)

def add_person(name, age, job, relations = {}):
my_group[name] = {"Age": age, "Job": job, "Relationship": relations }

def average_age():
age = 0
count_num = 0
for name, info in my_group.items():
age += info["Age"]
count_num += 1
average = age/count_num
print(f"The average age of {count_num} people in the group is {average}")

###Try some of the functions
#add_person("Rongru",24,"Student",{"John": "friend"})

#forget("Jill","Zalika")
#my_group


##Add the following comprehensive relations
#the maximum age of people in the group
#the average (mean) number of relations among members of the group
#the maximum age of people in the group that have at least one relation
#[more advanced] the maximum age of people in the group that have at least one friend

MaxiAge_comprehend = max([info["Age"] for name, info in my_group.items()])
Mean_relation = sum([len(info["Relationship"]) for name, info in my_group.items()])/len(my_group.keys())
MaxAge_relation = max([info["Age"] for name, info in my_group.items() if len(info["Relationship"]) >1])
MaxAge_friend = max([info["Age"] for name, info in my_group.items() if "friend" in info["Relationship"].values()])

my_group =