Q. Write a program that, depending upon the user's choice, either adds or removes an element from a Stack.
Answer =
stack = [ ] while True : com = input("Enter ( Push or Pop ) : ") if com == "push" or com == "Push" : num = int(input("Enter a number : ")) stack.append(num) elif len(stack) == 0 : print("Underflow") elif com == "pop" or com == "Pop" : stack.pop() yes = input ("Enter ( Yes or no ) : ") if yes == "No" or yes == "no": print("Thank you !!!!") break
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )