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

I want to make a loop which stucks user till the correct word entered, but when the correct word entered it doesn't show the proper output

I want to make a loop which stucks user till the correct word entered, but when the correct word entered it doesn’t show the proper output. Here what i have done

word = "High Sir"
        Letter = input("How is the Josh! \n")
        while Letter!= word:
            if Letter == word:
                Letter = ("Well Done! You are selected for next stage.")
            else:
                Letter = input("Bullshit, Enter Again\n")

>Solution :

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

It is not working because your condition for the loop is while Letter != word which means that you only enter the loop when Letter and word are NOT equal. Hence, when the user enters the correct word, Letter and word become equal and the loop condition fails which is why it does not enter the loop. You want something like this:

required_word = "High Sir"

while True:
    user_word = input("How is the Josh! \n")
    
    if user_word == required_word :
        print("Well Done! You are selected for next stage.")
        break
    else:
        print("Incorrect word! Try again")
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