laike9m/Cyberbrain

The output window closes automatically

anmol-gh opened this issue · 2 comments

I tried visualizing a stack with cyberbrain,here is the gif for the same.

New Project

CODE

max_size=1000
stack=[0 for i in range (max_size)]
top=0
from cyberbrain import trace

@trace
def push():
    global stack,top
    x=int(input('enter element to push into stack:'))
    if top>=max_size:
        print('cannot push.Stack is full,Overflow')
    else:
        stack[top]=x
        top+=1

@trace
def pop():
    global stack,top
    if top==0:
        print('Cannot pop.Stack is empty.Underflow')
    else:
        top-=1

@trace
def printstack():
    print(stack[:top])

while True:
    print('Please choose an operation')
    print('1. Push')
    print('2. Pop')
    print('3. Print')
    print('4. Exit')
    choice=int(input('Enter your choice'))
    if choice==4:
        break
    elif choice==3:
        printstack()
    elif choice==2:
        pop()
    elif choice==1:
        push()
    else:
        print('Please give a correct input')

Thanks for trying it out and providing feedbacks. As of now, you can only have one @trace decorator. This is documented here:
https://github.com/laike9m/Cyberbrain/blob/master/docs/Features.md#known-limitations

I'll make it more obvious in the readme.

Fixed by noting this in readme.