-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQuestion32.py
More file actions
56 lines (47 loc) · 1.86 KB
/
Copy pathQuestion32.py
File metadata and controls
56 lines (47 loc) · 1.86 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
# Question
# 32. Write a program to perform various list operations using menu driven operations.
# a. Add element c. Delete element e. Display list
# b. Modify element d. Add another list f. Exit
# Code
import string
actions = ["Add element", "Delete element", "Display list",
"Modify element", "Add another list", "Exit"
]
ml = []
while True:
for i, action in enumerate(actions):
actions[i] = action.lower()
title = "List Operator"
print("-" * len(title))
print(title)
print("-" * len(title))
print()
# print("current list:", ml)
print()
print("Operations:")
for i, action in enumerate(actions): print(string.ascii_letters[i], ":", action)
a = input("\n")
while string.ascii_letters.index(a.lower()) > len(actions):
a = input("Please enter from the given options:\n")
to_do_action = actions[string.ascii_letters.index(a.lower())]
print()
if to_do_action == 'add element':
ml.append(input("element:\n"))
elif to_do_action == 'delete element':
del ml[int(input("Please enter the index of the element to delete:\n"))] # TODO: Add a try and error condition in case entered number is not in the range of list
elif to_do_action == 'display list':
print(ml)
elif to_do_action == 'modify element':
i = int(input("Please enter the index of the element to modify:\n"))
ml[i] = input("The new element:\n")
elif to_do_action == 'add another list':
i = input("Please enter the elements seperated by comma\n")
for x in i.split(","): ml.append(x.strip())
elif to_do_action == 'exit':
print(
"Goodbye! Hopefully I was a good list operator") # The guy in black robes says yes u were a good operator! Only redditors will understand :D
break
print()
# Input
# Too big.
# Additional Comments