Skip to content

Instantly share code, notes, and snippets.

@morgvanny
Created May 10, 2024 21:19
Show Gist options
  • Save morgvanny/90504aa0f022b0fc83c902158fa9e748 to your computer and use it in GitHub Desktop.
Save morgvanny/90504aa0f022b0fc83c902158fa9e748 to your computer and use it in GitHub Desktop.
def main_menu():
while True:
print("Main Menu:")
print("1. Option 1")
print("2. Option 2")
print("3. Exit")
choice = input("Enter your choice: ")
if choice == "1":
submenu1()
elif choice == "2":
submenu2()
elif choice == "3":
print("Exiting program.")
break
else:
print("Invalid choice. Please try again.")
def submenu1():
while True:
print("Submenu 1:")
print("1. Sub-option 1")
print("2. Sub-option 2")
print("3. Go back to Main Menu")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
print("Executing sub-option 1 of Submenu 1.")
elif choice == "2":
print("Executing sub-option 2 of Submenu 1.")
elif choice == "3":
print("Returning to Main Menu.")
break
elif choice == "4":
print("Exiting program.")
exit()
else:
print("Invalid choice. Please try again.")
def submenu2():
while True:
print("Submenu 2:")
print("1. Sub-option A")
print("2. Sub-option B")
print("3. Go back to Main Menu")
print("4. Submenu 3")
choice = input("Enter your choice: ")
if choice == "1":
print("Executing sub-option A of Submenu 2.")
elif choice == "2":
print("Executing sub-option B of Submenu 2.")
elif choice == "3":
print("Returning to Main Menu.")
break
elif choice == "4":
submenu3()
else:
print("Invalid choice. Please try again.")
def submenu3():
while True:
print("Submenu 3:")
print("1. Sub-option X")
print("2. Sub-option Y")
print("3. Go back to Submenu 2")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
print("Executing sub-option X of Submenu 3.")
elif choice == "2":
print("Executing sub-option Y of Submenu 3.")
elif choice == "3":
print("Returning to Submenu 2.")
break
elif choice == "4":
print("Exiting program.")
exit()
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main_menu()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment