When I enter 4, the program does not ask to press Enter and does not close, but immediately writes what is in the else block, that is, the Unknown command. Type again Help solve the issue, well, you can still shorten the code
answer1 = input ('y/n: ') while True: if answer1 == 'y': while True: answer2 = str (input ('\nIf you want to exit type 4\n1/2/3/(4 close): ')) if answer2 == '1': print ('1') elif answer2 == '2': print ('2') elif answer2 == '3': print ('3') elif answer2 != '1' or answer2 != '2' or answer2 != '3' or answer2 != '4' or answer2 == '': print ('Unknown command. Type again') elif answer2 == '4': input ('Click Enter to exit') exit () continue elif answer1 == 'n': input ('Click Enter to exit') exit () else: print ('Unknown command. Type again') continue