Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stuck in loop if I start with false answer

name = "python"

name_answer = input("What is the name ? ")
while name_answer != name:
    input("No ! Again, What is the name ? ")
else:
    print("Correct answer")

If my first answer is "python", I get "correct answer". Untill then, everything is ok.

If I start with a false answer, for instance I input "abcd", the input "No ! Again, what is the name ? " appears. Here also, everything is OK.

But, the issue is I get stuck in the loop "No ! Again, what is the name ? " even if after that, I put the correct answer ("python").

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I don’t understand, I would like to get out that loop once I put "python" as an input even if I’m starting to input a false answer like "abcd".

>Solution :

The second input of the user (input("No ! Again, What is the name ? ")) wasn’t assigned to the name_answer variable

name = "python"

name_answer = input("What is the name ? ")
while name_answer != name:
    name_answer = input("No ! Again, What is the name ? ")
else:
    print("Correct answer")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading