小编Het*_*eth的帖子

使用switch语句在python中创建的堆栈

我使用switch创建了一个堆栈程序,但它似乎无法正常工作.它继续迭代推送方法.它甚至没有退出该计划.

global a
a=[]
def push():
    push_no=int(input("Enter number you want to push"))
    a.append(push_no)

def pop():
    poped_item=a.pop()
    print("Poped item {}".format(poped_item))


def display():
    print(a)  

def numbers_to_strings(a1): 
    switcher = { 
        1: push(), 
        2: pop(), 
        3: display(),
        4: quit()
    } 
    return switcher.get(a1, "nothing")


# Driver program 
if __name__ == "__main__": 
    while True:
        a1=int(input("ENTER WHICH OPERATION YOU WANT OT PERFORM 1-Push, 2-POP, 3-Display 4-quit"))
        numbers_to_strings(a1) 
Run Code Online (Sandbox Code Playgroud)

python stack switch-statement

0
推荐指数
1
解决办法
43
查看次数

标签 统计

python ×1

stack ×1

switch-statement ×1