Advertisements
Advertisements
प्रश्न
Consider a list named Nums which contains random integers.
Write the following user defined functions in Python and perform the specified operations on a stack named BigNums.
PushBig(): It checks every number from the listNumsand pushes all such numbers which have 5 or more digits into the stack,BigNums.PopBig(): It pops the numbers from the stack,BigNumsand displays them. The function should also display"Stack Empty"when there are no more numbers left in the stack.
For example: If the list Nums contains the following data:Nums = [213, 10025, 167, 254923, 14, 1297653, 31498, 386, 92765]
Then on execution of PushBig(), the stack BigNums should store:[10025, 254923, 1297653, 31498, 92765]
And on execution of PopBig(), the following output should be displayed:9276531498129765325492310025Stack Empty
कोड लेखन
Advertisements
उत्तर
def PushBig():
for n in Nums:
s=str(n)
if len(s) >= 5:
Nums.append(n)
def PopBig():
ifNums==[]:
print("Stack empty")
else:
for n in range(len(Nums)-1,-1,-1):
print(Nums[n])
else:
print("Stack empty")shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
