-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab14.py
More file actions
68 lines (64 loc) · 1.84 KB
/
Copy pathlab14.py
File metadata and controls
68 lines (64 loc) · 1.84 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
#python program to demonstrate list operation and method
#function to add stock items to inventory
stocklst=[]
def add():
global stocklst
item=input("enter stock item name ")
stocklst.append(item)
print(f"{item} has been added to stock list")
print("stock list is as follows")
print(stocklst)
print(f"the no of items present in the stock list={len(stocklst)}")
#function to remove stock item
def delete():
global stocklst
item=input("enter the stock item to be deleted ")
if item in stocklst:
stocklst.remove(item)
print(f"{item} has been removed from the stock lst")
else:
print(f"{item} has no found in the stock list")
#function to count stock item
def count():
global stocklst
item=input("enter the item to be continued")
c=stocklst.count(item)
print(f"{item} has found {c} times in stock list")
#function to list top N items
def display():
global stocklst
n=int(input("enter the nth no"))
x=stocklst[:n]
print(f"the first {n} items from stock list are as follows")
for e in x:
print(e)
#function to perform list filteration
def filter():
global stocklst
item=input("enter the item stock item which you want to create list")
filterlst=[e for e in stocklst if e==item]
print("the filtered list is as follows")
print(filterlst)
while True:
print("List Operations")
print("1.Add stock item")
print("2.Delete stock item")
print("3.count the stock item")
print("4.Display first N stock items")
print("5.Filter the stock list")
print("6.exit")
ch=int(input("enter the choice"))
if ch==1:
add()
elif ch==2:
delete()
elif ch==3:
count()
elif ch==4:
display()
elif ch==5:
filter()
elif ch==6:
break
else:
print("enter correct choice")