From 9e1edb5229e0fb3bfa57f6ba8c8cd1abf29ef432 Mon Sep 17 00:00:00 2001 From: Alex yuan <912599148@qq.com> Date: Thu, 29 Oct 2020 00:18:47 +0800 Subject: [PATCH] The function --- group.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/group.py b/group.py index e2ec347..4f2db99 100644 --- a/group.py +++ b/group.py @@ -2,4 +2,84 @@ # Your code to go here... -my_group = +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" + } + } +} + +# print(group['Jill']['age']) + +def findMaximunAge(): + name = 'Jill' + temp = group['Jill']['age'] + for people in group: + if group[people]['age'] > temp: + name = people + temp = group[people]['age'] + return name + +def mean_realationship(): + temp = 0 + PeopleNo = 0 + for people in group: + PeopleNo = PeopleNo + 1 + temp = len(group[people]['relations'])+temp + return temp/PeopleNo + +def MaxAgeOnerelationship(): + name = 'Jill' + temp = group['Jill']['age'] + for people in group: + if group[people]['age'] > temp and len(group[people]['relations']) >=1: + name = people + temp = group[people]['age'] + return name + +def MaxAgeOneFriend(): + name = 'Jill' + temp = group['Jill']['age'] + for people in group: + if group[people]['age'] > temp and len(group[people]['relations']) >=1: + for index in group[people]['relations']: + if group[people]['relations'][index] == 'friend': + name = people + temp = group[people]['age'] + return name + + +print(findMaximunAge()) +print(mean_realationship()) +print(MaxAgeOnerelationship()) +print(MaxAgeOneFriend()) + + + +