Just starting out here soz. I've been trying to make a menu with several options (def logged():) by entering a number and it would jump to that function with a purpose. However, I cannot seem to call the designated functions with the if statements put in a while loop, and instead, it jumps back to the menu() function when the logged function is supposed to keep running through the while loop forever.
When I enter the corresponding number in the menu of logged(), it should call that specific function, but it just jumps way back to the 1st menu. I just can't seem to get the two menus to loop forever without them jumping back and forth. So how exactly do I make two while loops loop forever separately and not into each other?
def menu():
mode = input("""Choose options:\n
a) Test1 Calls logged() function
b) Test2
Enter the letter to select mode\n
> """)
return mode
def test1():
print("Test1")
logged()
def test2():
print("Test2")
def logged(): #Logged menu is supposed to run through a while loop and not break out when reached.
print("----------------------------------------------------------------------\n")
print("Welcome user. ")
modea = input("""Below are the options you can choose:\n
1) Function1
2) Function2
3) Function3
4) Exit
\n
Enter the corresponding number
> """).strip()
return modea
def funct1(): #EXAMPLE FUNCTIONS
print("Welcome to funct1")
def funct2():
print("Welcome to funct2")
def funct3():
print("Welcome to funct3")
#Main routine
validintro = True
while validintro:
name = input("Hello user, what is your name?: ")
if len(name) < 1:
print("Please enter a name: ")
elif len(name) > 30:
print("Please enter a name no more than 30 characters: ")
else:
validintro = False
print("Welcome to the test program {}.".format(name))
#The main routine
while True:
chosen_option = menu() #a custom variable is created that puts the menu function into the while loop
if chosen_option in ["a", "A"]:
test1()
if chosen_option in ["b", "B"]:
test2()
else:
print("""That was not a valid option, please try again:\n """)
while True:
option = logged()
if option == "1":
funct1()
elif option == "2":
funct2()
elif option == "3":
funct3()
elif option == "4":
break
else:
print("That was not a valid option, please try again: ")
print("Goodbye")