我使用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)
答案 0 :(得分:5)
在myAdapter.setListener {
supportFragmentManager
.beginTransaction()
.replace(MainActivity.FRAGMENT_CONTAINER, TextScreen())
.commit()
}
定义中,您已经评估了字典中的功能。试试:
numbers_to_strings