Advertisement
Shailrshah

Stack

Sep 13th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. __author__ = 'Shail'
  2. a = list();
  3. n = int(input("Size of stack: "));
  4. count = 0;
  5. while True:
  6.     print(a[:]);
  7.     choice = int(input("1.Push 2.Pop 3.Exit: "));
  8.     if choice == 1:
  9.         if count == n: print("Stack is full.");
  10.         else:
  11.             a.append(input("Enter a number to push: "));
  12.             count += 1;
  13.     elif choice == 2:
  14.         if count == 0: print("Stack is empty.");
  15.         else:
  16.             del a[count-1];
  17.             count -= 1;
  18.     elif choice == 3:
  19.         break;
  20.     else: print("Enter 1, 2, or 3.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement