There is a piece of code:

for element in questions: while answer != 'д' and answer != 'н': answer = input(element+': ') answer = (((answer[0].lower()).replace('y', 'д')).replace('n', 'н')) if answer != 'д' and answer != 'н': print('Ответ невозможно принять.') 

With a successful response, the for loop is also interrupted. If you remove the while for loop, it works fine. Please explain why this is happening and where I made a mistake.

  • Language - Python 3 - Gra4

2 answers 2

 def parse_answers(question): while True: answer = input('{}: '.format(question))[0].lower() if answer not in ('y', 'n'): print('Ответ невозможно принять') continue else: return answer questions = ('yes?', 'no?') for question in questions: answer = parse_answers(question) print(answer) 
  • Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky

Understood the error, added at the end of the answer = ''

  • better in a separate function, for q in questions: ask_question(q) question to the user: for q in questions: ask_question(q) (then the answer from the previous iteration will not interfere). The condition can be simplified: if not answer.casefold().startswith(('yes','no', 'да', 'нет')): print('Ответ невозможно принять.') else: break - jfs