好的,所以你犯了一些错误(很明显),没什么大不了的,每个人都得开始学习。
最大的问题是你进入菜单循环(你有第二个while循环),但从不做任何事情来退出它。我还评论了其他一些变化。我不是100%确定你在某些地方做什么...但是...
我认为this is what you were going for though,我评论了这些变化。有一些奇怪的东西,我只是留下,因为我认为这是意图。
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 = False # I like it this way
while not 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 = True
print("Welcome to the test program {}.".format(name))
#The main routine
validintro = False # need a way out
while not validintro:
chosen_option = menu() #a custom variable is created that puts the menu function into the while loop
validintro = True # start thinking we're okay
if chosen_option in ["a", "A"]:
test1() # you're calling this, which calls the logged thing, but you do nothing with it
# I just left it because I figured that's what you wanted
elif chosen_option in ["b", "B"]: # You want an elif here
test2()
else:
print("""That was not a valid option, please try again:\n """)
validintro = False # proven otherwise
validintro = False
while not validintro:
validintro = True
option = logged()
print(option)
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: ")
validintro = False
print("Goodbye")