-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSTACKPRG.py
91 lines (82 loc) · 2.05 KB
/
STACKPRG.py
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
# def isEmpty(stk):
# if stk==[]:
# return True
# else:
# return False
# def Push(stk,item):
# stk.append(item)
# top=len(stk)-1
# def Pop(stk):
# if isEmpty(stk):
# return "Underflow"
# else:
# item=stk.pop()
# if len(stk)==0:
# top=None
# else:
# top=len(stk)-1
# return item
# def Peek(stk):
# if isEmpty(stk):
# return "underflow"
# else:
# top=len(stk)-1
# return stk[top]
# def Display(stk):
# if isEmpty(stk):
# print("Stack Empty")
# else:
# top=len(stk)-1
# print(stk[top],"<-top")
# for a in range (top-1,-1,-1):
# print(stk[a])
# #___main______
# Stack=[]
# top=None
# while True:
# print("Menu for stack operation")
# print("1.push")
# print("2.Pop")
# print("3.Peek")
# print("4.Display Stack")
# print("5.Exit")
# ch=int(input("Enter your choice(1-5):"))
# if ch==1:
# name=input("Enter Your Name:")
# roll=int(input("Enter ur roll no"))
# item=[name,roll]
# Push(Stack,item)
# elif ch==2:
# item=Pop(Stack)
# if item=="Underflow":
# print("Underflow!Stack is Empty!")
# else:
# print("Popped item is ",item)
# elif ch==3:
# item=Peek(Stack)
# if item=="underflow":
# print("Underflow! Stack is Empty")
# else:
# print("Topmost item is ",item)
# elif ch==4:
# Display(Stack)
# elif ch==5:
# break
# else:
# print("Invalid Choice")
Only3_5=[]
def Push3_5(N):
if N%3==0 or N%5==0:
Only3_5.append(N)
NUM=[]
for i in range (5):
n=int(input("Enter an integer:"))
NUM.append(n)
Push3_5(n)
while True:
if len(Only3_5)==0:
print("Empty Stack")
break
else:
print(Only3_5.pop(),"",end='')
print(NUM)