I want to produce an endless loop that would to different things depending on some user input. When the .py is executed the loop starts and does some 'main' programm and the input window opens for the user. When typing 'alt1' the loop jumps in to the function 'main_alt1' and so on.
user_input = 'main'
user_input = input()
while True:
if user_input == 'main'
main()
elif user_input == 'alt1'
main_alt1()
elif user_input == 'exit'
exit()
The problem here is that the input is either given once before the loop (like in the example) or it stops the loop when the input is inside the loop until the input is given. Does anyone has a smart way to do something like that. It doesn't need to be with input().
input()to be inside the loop, before theifstatement. Otherwise the same function will be called in an infinite loop, which I doubt you want.main()to be called in an infinite loop since it needs to check something every few seconds.user_inputvariable. The other is the main loop which reads the value ofuser_input, as it currently does. Check out the threading module. It might be possible usingasync, but I'm not too familiar with it yet.