-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogramContact.py
More file actions
56 lines (36 loc) · 1.57 KB
/
programContact.py
File metadata and controls
56 lines (36 loc) · 1.57 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import classContact
def main():
try:
friends_file = open("contactsLab5.txt", 'r')
friend_list = []
name = friends_file.readline()
while name != "":
name = name.rstrip('\n')
birthdate = friends_file.readline().rstrip('\n')
a_friend = classContact.Contact(name, birthdate)
friend_list.append(a_friend)
name = friends_file.readline()
friends_file.close()
display_friends(friend_list)
except FileNotFoundError:
print("File was not found")
except Exception as err:
print("Error:", err)
def display_friends(chums):
# Get current date
todays = input("Enter current date in the format 'month d, yyyy': ")
# initiates total age to use in average age calculation
total_age = 0
print(format("Name", '20'), format("Age", '7'),
format("Season", '10'), format("Leap Year?", '5'))
print(format("----------", '20'), format("-----", '7'),
format("------", '10'), format("---------", '5'))
for i in range(len(chums)):
ages = int(chums[i].calculate_age(todays))
total_age += ages
print(format(chums[i].get_name(), '20'), \
format(str(chums[i].calculate_age(todays)), '7'), \
format(chums[i].find_season(), '10'), \
format(chums[i].is_leap_year(), '5'))
print("\nAverage age of contact is ", total_age // len(chums))
main()