Nov-09-2019, 12:59 PM
This is how would set it up,and do not use
All is in function will always fall back to menu function that run the main loop,here can do new task or Quit out.
%s
string formatting anymore.All is in function will always fall back to menu function that run the main loop,here can do new task or Quit out.
def file_deletion(): file_to_delete = input('File to delete: ') print(f'Deleting <{file_to_delete}>\n') input('Push enter to retun to menu') def file_creation(): pass def show_menu(): print ("\nExample menu") print ("-----------------") print ("1) File deletion") print ("2) File creation") print ("Q) Exit\n") def menu(): while True: show_menu() choice = input('Enter your choice: ').lower() if choice == '1': file_deletion() elif choice == '2': file_creation() elif choice == 'q': return else: print(f'Not a correct choice: <{choice}>,try again') if __name__ == '__main__': menu()
Output:E:\div_code
λ python file_menu.py
Example menu
-----------------
1) File deletion
2) File creation
Q) Exit
Enter your choice: 999
Not a correct choice: <999>,try again
Example menu
-----------------
1) File deletion
2) File creation
Q) Exit
Enter your choice: 1
File to delete: hello.txt
Deleting <hello.txt>
Push enter to retun to menu
Example menu
-----------------
1) File deletion
2) File creation
Q) Exit
Enter your choice: q
E:\div_code