Python Console App | Is there a better way to go back a page? I have a system for going back to a previously-visited page in a Python console application; it works well enough, but I feel that there could be a prettier way of doing it. Does anyone have any suggestions to improve what I have below?
def main():
    try:
        while True:
            print('Main Menu\n')

            option = input('page 1, page 2, quit\n')

            if option in ['1', 'one']:
                menu_stack.append(0)
                page_one()
            elif option in ['2', 'two']:
                menu_stack.append(0)
                page_two()
            elif option in ['q', 'quit']:
                quit()
            else:
                print('Invalid input, please try again\n')
                sleep(1)

    except KeyboardInterrupt:
        quit()

Very similar to the main menu page, below is page 1:
def page_one():
    while True:
        clear_terminal()

        print('Page One\n')

        option = input('Page 2, back\n')

        if option in ['2', 'two']:
            menu_stack.append(1)
            page_two()
        elif option in ['b', 'back']:
            menu_checker()
        else:
            print('Invalid input, please try again\n')
            sleep(1)

menu_checker() calls the other pages based on what pops from the stack:
def menu_checker():
    page = menu_stack.pop()

    if page == 1:
        page_one()
    elif page == 2:
        page_two()
    elif page == 0:
        main()
    else:
        print('Error')

Does anyone have any better ideas/solutions? Even though it doesn't cause any issues (as far as I am aware), I feel what I have is kind of clunky and could be improved.
I'm thinking there are a few different approaches you could take here.
The stack was inside you all along
It may not be the most flexible of approaches, but the way things are right now, your pages are just functions. And guess what? Your program already has a stack of functions -- you navigate it by calling functions and returning from them! You don't get a whole lot of information about where you'll end up if you return, but if that's not a problem, you might be able to just get rid of menu_checker and menu_stack altogether -- if the user wants to go back, you just return.
For example, your page_one could simply look like
def page_one():
    while True:
        clear_terminal()

        print('Page One\n')

        option = input('Page 2, back\n')

        if option in ['2', 'two']:
            page_two()
        elif option in ['b', 'back']:
            return
        else:
            print('Invalid input, please try again\n')
            sleep(1)

It's not the fanciest-looking perhaps, but it's easy to implement, easy to understand and does the job just fine.
Where do you want to go?
But maybe that isn't good enough. It might be nice if the &quot;back&quot; option could say something like &quot;Back (to page 1)&quot; depending on what the stack looks like, for example. Or maybe you'd like to also have a &quot;forward&quot; option in case the user accidentally presses &quot;back&quot; too many times. Or maybe there's another reason you don't want to use the call stack for this. That's fine too.
Another option could be to move the navigation logic from the individual menus into a single core loop. Each menu then returns which menu it thinks you should go to next.
For example, we might be looking at something like this:
def main():
    menu_stack = [main_menu]

    while menu_stack:
        current_menu = menu_stack[-1]

        next = current_menu(option)

        if next:
            menu_stack.append(next)
        else:
            menu_stack.pop()

With menus looking a lot like the previous ones, but instead of calling the next menu like page_two() they return it like return page_two. Or perhaps return None if we should go back.
Classy
Personally, though, I think there are some tasks (like asking for input) that should be the responsiblity of the app itself rather than the menus. The menu can know what it looks like and how to navigate based on input, but the core loop asks it for help and then handles those things on its own terms.
def main():
    menu_stack = [main_menu]

    while menu_stack:
        current_menu = menu_stack[-1]

        clear_terminal()

        print(current_menu.text)

        option = input(current_menu.prompt)

        try:
            next = current_menu.get_next_menu(option)

            if next:
                menu_stack.append(next)
            else:
                menu_stack.pop()
        except ValueError as e:
            print(&quot;Invalid input, please try again&quot;)
            sleep(1)

Defining a nice Menu class is left as an exercise for the reader.