-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram5B1.py
More file actions
26 lines (26 loc) · 803 Bytes
/
Program5B1.py
File metadata and controls
26 lines (26 loc) · 803 Bytes
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
# Program5B1
# Matthew Ancelin
# this program will create a dictionary from a file
def make_dictionary(filename):
dict = {}
with open(filename, 'r') as file:
for line in file:
key, value = line.split()
dict[key] = value
return dict
filename = 'LAB5B1.txt'
dictionary = make_dictionary(filename)
print(dictionary)
namecheck = input("Enter a name to search for: ")
if namecheck in dictionary:
print ("Yes, that name is in there")
else:
print ("Sorry, did not find that name")
age = input("Enter an age to count ")
agecount = 0
v = list(dictionary.values())
for i in range(len(dictionary)):
if age == v[i]:
agecount += 1
print ("that age appears ", agecount, " times in this dictionary")
print ("The oldest person is ", max(v), " years old.")