Q. Give the necessary declaration of a list implemented Stack containing float type numbers. Also, write a user-defined function to pop a number from this Stack.


Answer =

def stackpop(stack):
    stack.pop()
stack = [ ]
while True :
    print()
    print("Enter your choice  as per given -")
    print("1. For insert data Enter 'insert' ")
    print("2. For delete data enter 'delete' ")
    print("3. For Exit enter 'exit' ")
    print()
    user = input("Enter your choise :- ")
    if user == "insert" :
        data = float(input("Enter the float number :- "))
        stack.append(data)
    elif user == "delete" :
        if stack == [ ]:
            print("UnderFlow")
        else :
            stackpop(stack)
    else :
        break
    print("Now our stack = ", stack)

Output :-

Enter your choice as per given -
1. For insert data Enter 'insert' 
2. For delete data enter 'delete' 
3. For Exit enter 'exit' 
Enter your choice:- insert
Enter the float number :- 55.1
Now our stack =  [55.1]

Enter your choice as per given -
1. For insert data Enter 'insert' 
2. For delete data enter 'delete' 
3. For Exit enter 'exit' 
Enter your choice:- insert
Enter the float number :- 875.669
Now our stack =  [55.1, 875.669]

Enter your choice as per given -
1. For insert data Enter 'insert' 
2. For delete data enter 'delete' 
3. For Exit enter 'exit' 
Enter your choice:- delete
Now our stack =  [55.1]

Enter your choice as per given -
1. For insert data Enter 'insert' 
2. For delete data enter 'delete' 
3. For Exit enter 'exit' 
Enter your choice:- insert
Enter the float number :- 44547
Now our stack =  [55.1, 44547.0]

Enter your choice as per given -
1. For insert data Enter 'insert' 
2. For delete data enter 'delete' 
3. For Exit enter 'exit' 
Enter your choice:- exit

>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post