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

while loop keeps executing

I don’t understand why the while keeps executing even though I have written the name "gabriel" or the name "tommy"

nombre = ""
while nombre != "gabriel" or nombre !="tommy":
nombre = input()
if nombre != "gabriel" or nombre != "tommy":
    print("ingrese su nombre nuevamente")
else:
    print("su nombre es ")
    break

>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

You are using or where you should be using and. However, you are also making two checks where you only need one, and initializing nombre unnecessarily. Consider this instead:

while True:
    nombre = input()
    if nombre != "gabriel" and nombre != "tommy":
        print("ingress su nombre nuevamente")
    else:
        print("su nombre es", nombre)
        break

or using or correctly:

while True:
    nombre = input()
    if nombre == "gabriel" or nombre == "tommy":
        print("su nombre es", nombre)
        break

    print("ingress su nombre nuevamente")
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