CBSE Class 12 Computer Science Question 4 of 18

Practice Paper — Question 14

Back to all questions
14
Question

Question 14

Write a function Push() which takes number as argument and add in a stack "MyValue".

Solution
MyValue = []

def Push(number):
    MyValue.append(number)
    print(number, "pushed to the stack.")

Push(5)
Push(10)
Push(15)
Output
5 pushed to the stack.
10 pushed to the stack.
15 pushed to the stack.
Answer

MyValue
=
[]
def
Push
(
number
):
MyValue
.
append
(
number
)
print
(
number
,
"pushed to the stack."
)
Push
(
5
)
Push
(
10
)
Push
(
15
)
Output
5 pushed to the stack.
10 pushed to the stack.
15 pushed to the stack.