-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw7.py
More file actions
93 lines (71 loc) · 2.96 KB
/
hw7.py
File metadata and controls
93 lines (71 loc) · 2.96 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
''' Assignment
This assignment will include the following:
Finish walking through this lecture to copy/paste the beginning of the script you will need for your homework.
(Links to an external site.)Links to an external site.
Finish the user option to delete an entry from the dictionary by removing the "pass" statements and adding
code to delete a user by name (extra challenge: can you figure out how to delete a user by name OR username?)
Finish the user option to lookup a username by name by removing the "pass" statement and adding code to find
a user by name
Run the script and make sure each option works
Add exception handling to each user input option.
Add doc strings to the script and comment the code.
Push your finished script to your personal, publicly accessible Github repo.
Submit a link to the Github repo containing your script on canvas.
Criteria
This criterion is linked to a Learning Outcome User can delete an entry from the dictionary. 25pts
This criterion is linked to a Learning Outcome User can lookup a username by name. 25pts
This criterion is linked to a Learning Outcome Each user option has exception handling. 25pts
This criterion is linked to a Learning Outcome Script contains helpful doc strings and comments 10pts
This criterion is linked to a Learning Outcome Finished script successfully uploaded to Github 25pts
'''
from sortedcontainers import SortedDict
def print_menu():
print('1. Print Users')
print('2. Add a User')
print('3. Remove a User')
print('4. Lookup a Phone Number')
print('5. Quit')
print()
# Create dictionary with key = Names, value = user_name
usernames = SortedDict()
usernames['Summer'] = 'summerela'
usernames['William'] = 'GoofyFish'
usernames['Steven'] = 'LoLCat'
usernames['Zara'] = 'zanyZara'
usernames['Renato'] = 'songDude'
# setup counter to store menu choice
menu_choice = 0
# display your menu
print_menu()
# as long as the menu choice isn't "quit" get user options
while menu_choice != 5:
# get menu choice from user
menu_choice = int(input("Type in a number (1-5): "))
# view current entries
if menu_choice == 1:
print("Current Users:")
for x, y in usernames.items():
print("Name: {} \tUser Name: {} \n".format(x, y))
# add an entry
elif menu_choice == 2:
print("Add User")
name = input("Name: ")
username = input("User Name: ")
usernames[name] = username
# remove an entry
elif menu_choice == 3:
print("Remove User")
name = input("Name: ")
if name in usernames:
pass # delete that entry
# view user name
elif menu_choice == 4:
print("Lookup User")
name = input("Name: ")
if name in usernames:
pass # print the username
else:
pass # print username not found
# is user enters something strange, show them the menu
elif menu_choice != 5:
print_menu()