0% found this document useful (0 votes)
22 views

PROGRAM 1-1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

PROGRAM 1-1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

PROGRAM 1

• BCCI has created a dictionary containing top players and


their runs as key value pairs of cricket team. Write a
program, with separate user defined functions to perform
the following operations:
• ● Push the keys (name of the players) of the dictionary into
a stack, where the corresponding value (runs) is greater
than 49.
• ● Pop and display the content of the stack.
• For example:If the sample content of the dictionary is as
follows:
• SCORE={"KAPIL":40, "SACHIN":55, "SAURAV":80,
"RAHUL":35, "YUVRAJ":110, }
• The output from the program should be:
SCORE={"KAPIL":40, "SACHIN":55, "SAURAV":80, "RAHUL":35,
"YUVRAJ":110 }
def PUSH(S,R):
S.append(R)
def POP(S):
if S!=[ ]:
return S.pop()
else:
return None #Message
ST=[]
for k in SCORE:
if SCORE[k]>49:
PUSH(ST,k)
while True:
if ST!=[]:
print(POP(ST),end=" ")
else:
break
PROGRAM 2
Vikram has a list containing 10 integers. You need to help
him create a program with separate user defined
functions to perform the following operations based on
this list.
● Traverse the content of the list and push the ODD
numbers into a stack.
● Pop and display the content of the stack.
For Example:
If the sample Content of the list is as follows:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]

def PUSH(S,N):
S.append(N)
def POP(S):
if S!=[]:
return S.pop()
else:
return None
ST=[]
for k in N:
if k>33:
PUSH(ST,k)
while True:
if ST!=[]:
print(POP(ST),end=" ")
else:
break
YASH MOTORS have a dictionary of top performer EMPLOYEES
and their SALES of as key value pairs of COMPANY. Write a
program, with separate user defined functions to perform the
following operations:

● Push the keys (name of the EMPLOYEE) of the dictionary into


a stack, where the
corresponding value (SALES) is greater than 500000.
● Pop and display the content of the stack.

For example:
If the sample content of the dictionary is as follows:
SALES={"SUNIL":700000, "ROHIT":400000, "RAJEEV":350000,
"MAYANK":750000,"RAHUL":1000000, }
The output from the program should be:
SALES={"SUNIL":700000, "ROHIT":400000, "RAJEEV":350000,
"MAYANK":750000, "RAHUL":1000000 }

def PUSH(STK,S):
STK.append(S)
def POP(STK):
if STK!=[]:
return STK.pop()
else:
return None
ST=[]
for k in SALES:
if SALES[k]>500000:
PUSH(ST,k)
while True:
if ST!=[]:
print(POP(ST), end=" ")
else:
break
Saroj have a list of 10 numbers . You need to
help him create a program with separate user
defined functions to perform the following
operations based on this list.

● Traverse the content of the list and push the


numbers into a stack which are divisible by 5.
● Pop and display the content of the stack.
For Example:

If the sample Content of the list is as follows:


N=[2,5,10,13,20,23,45,56,60,78]
Sample Output of the code should be:
N= [2,5,10,13,20,23,45,56,60,78]
def PUSH(S,N):
S.append(N)
def POP(S):
if S!=[]:
return S.pop()
else:
return None
ST=[]
for k in N:
if k%5==0:
PUSH(ST,k)
while True:
if ST!=[]:
print(POP(ST),end=" ")
else:
break
A company having dictionary of various Departments
and Number of computers (PC) available as key value
pairs. Write a program, with separate user defined
functions to perform the following operations:

● Push the keys (name of the Department) of the


dictionary into a stack, where the corresponding value
(Number of PC) is 25 or more.
● Pop and display the content of the stack.

For example:
If the sample content of the dictionary is as follows:
SETUP={"HR":10, "QUALITY":25, "SUPPORT":50,
"PRODUCTION":20, "SUPPLY":25,}
The output from the program should be:
SETUP={"HR":10, "QUALITY":25, "SUPPORT":50,
"PRODUCTION":20,"SUPPLY":25, }

def PUSH(STK,S):
STK.append(S)
def POP(STK):
if STK!=[]:
return STK.pop()
else:
return None
ST=[]
for k in SETUP:
if SETUP[k]>=25:
PUSH(ST,k)
while True:
A programmer wants to prepare a stack from given list
of integer elements only for the numbers which are
divisible by 3. Help him create a program with a user
defined functions to perform the following operations
based on this list.

● Traverse the content of the list and push the


numbers into a stack which are divisible by 3.
● Pop and display the content of the stack.

For Example:
If the sample Content of the list is as follows:
N=[3,5,10,13,21,23,45,56,60,78]
Sample Output of the code should be:
N=[3,5,10,13,21,23,45,56,60,78]
def PUSH(S,N):
S.append(N)
def POP(S):
if S!=[]:
return S.pop()
else:
return None
ST=[]
for k in N:
if k%5==0:
PUSH(ST,k)
while True:
if ST!=[]:
print(POP(ST),end=" ")
else:
break

You might also like