Skip to content
Advertisement

I want to return to “input” after type wrong character in python [closed]

I want to return to the “input” after the user type another character that is not “n” string, The entry data is a “Input” that make the user press enter to continue or type “n”, but if the user type another string, the console close

_WriteList = input("Write a textfile with the file list? (Enter) Yes or (n) No: ")

if bool(_WriteList) == False:
    sevenZipListWrite()
elif _WriteList == "n":
    sevenZipList()

Advertisement

Answer

You should do it using a while loop like this

_WriteList = input("Write a textfile with the file list? (Enter) Yes or (n) No: ")

while _WriteList != 'n':
  sevenZipListWrite()
  _WriteList = input("Write a textfile with the file list? (Enter) Yes or (n) No: ")

sevenZipList()
Advertisement