'while loop keeps executing [duplicate]
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 1:[1]
nombre != "gabriel" or nombre !="tommy"
No matter what the user enters, this condition will always be true.
If they enter "gabriel", then it is not equal to "tommy".
If they enter "tommy", then it is not equal to "gabriel".
Use and instead of or.
Solution 2:[2]
Below statement always return true and the loop won't stop. I guess u want to use "and" instead or in below statement.
nombre != "gabriel" or nombre != "tommy"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | John Gordon |
| Solution 2 | Jack Ng |
