Python Week - 10
Python Week - 10
Week : 2
Programs on Tnherntance
and PolymorphtSm
/s l24
on stacks and
Frogams
Queues
Ttle :
Date: 27lo3l2t
Page No: 12
Output: PROGRAr1S ON STACKS NO QUEUEs
1. Push
2. POP 1. Python programn to tmplerment stack
3 PeekK
#Stack
41splay def push (1):
S Cuit
data int (input ((Enter the value:)
Entr n:1 S. append (dato)
Entr the value: 10
1. Purh def op():
2. Pop if lenl) 0:
3. Peek print (stack is underflow)
else :
print (" The seletd element i
énttr n:
Cn ter the val ue : Jo
def peek0:
(f (en()= 0:
1.Push
print (^ Stack tr underflo)
3 Pee else:
3 Ftek
Ihlle (1):
Gnttr n:3
20 prtnt1.ush\n3 Po/n3.feern4 Diplays Calt")
he tep tlenent ef stax n lot (rput("cotr n:))
1ush
3 Peek puch (stac)
4. Aitplay elrr (n2):
PoP(stack)
Cnttr n: 4 eli( (n:i):
Ihestack elemenh at: Peek (stack)
J.push ellf (n: 4):
3. Peek ditploy (nack)
4. AIplay eur (n: ) :
exit (o)e
en ter n: S
Date: 2?logl 2024
Title:
Page No.: y
Output: 2. Pythorn prugramn tb imple ment @ueue .
1. EnQueue #@ueue
e Quene def Enucuc (4):
3 Peek data : lnt (nput ("enter the value: ))
4- Aplay 4 append (dlata)
S Gt
def edueue (a)
Enter
érr your cholte:4
10
En ttr the vale :
1. en@uee
print ("@ueue s underflow)
tlse:
R e @ue ne
print ("Bele ted element is:" 2Poplo)
3. Peek
def peek(q):
f (en(a) :2 0:
éntr yout choice: 1 print ("aucue i! urderfloo )
else:
Gnttr the value : 20
1. En Quene
print( The frtt elernernt of quene i:"0)
def diiplay (a):
3. Peek if ten():= 0:
print/^ Queue Is undeyflow)
Senit
print (4)
Gntr your chol le :1
enter the value:30 #Arier Code
i.énOuee
queue C]
J e Quee
JIhile (2):
3.Peek
print(4ndueue v2 Dequeue\ns. Peck\n4. Driplay in s. fatt')
Si east. n: tnt (nput(entr your cholre :))
Title :
ypuY chotte : a
enter your
Sclettd element !: 10
1. enQuee nQue uclaueu)
3- Pee
De@ueue (q ucue)
1. Enuene
3.Peek