Issue
async def main_menu():
menu_active = True # Variable to control the display of the menu
while menu_active:
print("\nMain Menu:")
print("1. Activate script")
print("2. Account authorization")
print("3. Exit")
choice = input("Enter the option number: ")
os.system('cls')
if choice == '1':
headless_choice = input("Do you want to use headless mode? (yes/no): ").lower() == 'yes'
driver = initialize_browser(headless=headless_choice)
driver.get("https://my.site")
os.system('cls')
elif choice == '2':
authorize_system()
elif choice == '3':
print("Exiting the program...")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
asyncio.run(main_menu())
By logic, after I select function 1, the script launches the browser and should perform its actions, and the menu should not appear again because I have already chosen to execute the function. How do I make it so that after I choose function 1, the menu does not appear again?
break , while flags,
Solution
Since menu_active
is still True
after selecting option 1, the loop runs again and again. Either set menu_active
to False
after selecting any option or break
like you did in option 3
Answered By - Just for fun
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.