-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict_obj.py
More file actions
43 lines (35 loc) · 1.12 KB
/
Copy pathdict_obj.py
File metadata and controls
43 lines (35 loc) · 1.12 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
# Example 6
def main():
# Create a dictionary with student IDs as
# the keys and student names as the values.
students = {
"42-039-4736": "Clint Huish",
"61-315-0160": "Michelle Davis",
"10-450-1203": "Jorge Soares",
"75-421-2310": "Abdul Ali",
"07-103-5621": "Michelle Davis",
"81-298-9238": "Sama Patel"
}
# Get a student ID from the user.
id = input("Enter a student ID: ")
# Lookup the student ID in the dictionary and
# retrieve the corresponding student name.
name = students.get(id)
if name:
# Print the student name.
print(name)
# Remove the student that the user
# specified from the dictionary.
students.pop(id)
else:
print("No such student")
print()
# Use a for loop to print each key value pair in the
# dictionary. Of course, the code in the body of a loop
# can do much more with each key value pair than simply
# print it.
for key, value in students.items():
print(key, value)
# Call main to start this program.
if __name__ == "__main__":
main()