-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_adv.py
More file actions
executable file
·77 lines (67 loc) · 1.86 KB
/
list_adv.py
File metadata and controls
executable file
·77 lines (67 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
""" this program shows the use of list : adding item, removing item, printing it (iterating), clearing it """
import sys
thisislist = ["apple","banana"]
print("this is the initial list ",thisislist)
print("this is the length of the list ",len(thisislist))
def Additem():
item = str(input("Enter the name of the element that you want to add = "))
thisislist.append(item)
print(thisislist)
menu()
def RemItem():
item = str(input("Enter the name of the element that you want to remove = "))
thisislist.remove(item)
print(thisislist)
menu()
def PrintList():
for x in thisislist:
print(x)
menu()
def CheckList():
search = str(input("Enter the item u wanna search: "))
if search in thisislist:
print("Yes it is present")
else:
print("It is not present")
print(thisislist)
menu()
def AddItemPos():
item = str(input("Enter the item u want to Add : "))
pos = int(input("Enter the position Where u wanna add the item : "))
thisislist.insert(pos,item)
print(thisislist)
menu()
def ClearList():
thisislist.clear()
print(thisislist)
menu()
def menu():
print('''
0) Quit
1) Add an element to the list
2) Add an item at a particular position
3) Remove an element from the list
4) Display the list
5) Check if an item exists
6) Clear the list
''')
selection = int(input("What do you want to do: "))
if selection == 0:
sys.exit()
elif selection == 1:
Additem()
elif selection == 2:
AddItemPos()
elif selection == 3:
RemItem()
elif selection == 4:
PrintList()
elif selection == 5:
CheckList()
elif selection == 6:
ClearList()
else:
print("Invalid input")
menu()
### to use this as a module in other programs uncomment all the
### lines with menu()