While statment loop in python
<p>I am learning python, and I am stuck in an infinite while loop in the following code.</p>

<pre><code>A = input("Hello what is your name? ")
D = input("What is today's date? ")
B = input("Did you have a good day [y/N]")
while B != "y" or B != "Y" or B != "N" or B != "n":
    B = input("Did you have a good day [y/N]")
else:
    if B == "Y" or B == "y":
        print(A + ", ")
        C = input("Tell me about your day ")
        with open("Start.txt", "a") as infile:
            infile.write("\n")
            infile.write(A)
            infile.write(" ran Start.py and said he had a good day on ")
            infile.write(D)
            infile.write(".")
            infile.write("\n    He reports today:\n        ")
            infile.write(C)
    elif B == "N" or "n":
        print(A + ", ")
        C = input("Tell me about your day ")
        with open("Start.txt", "a") as infile:
            infile.write("\n")
            infile.write(A)
            infile.write(" ran Start.py and said he had a bad day on ")
            infile.write(D)
            infile.write(".")
            infile.write("\n    He reports today:\n        ")
            infile.write(C)
</code></pre>

<p>The problem happens when B is compared to see if it is equal to Y, y, N, or n
but it still no matter what input I give it for B sticks me into the while statement and keeps me there.</p>

<p>Lets use a simplified version of your while loop.</p>

<pre><code>while B != "Y" or B != "y":
    # ...
</code></pre>

<p>There is no way that this will ever evaluate to <code>False</code>.</p>

<p>If B was set to <code>Y</code> then <code>B != "Y"</code> would be <code>False</code>, but <code>B != "y"</code> would be <code>True</code>.</p>

<p>I think, in this case, it might be cleaner to do something like</p>

<pre><code>while B not in ["y", "Y", "n", "N"]:
    # ...
</code></pre>

<p>Which will then repeat until the input is one of the characters in your list.</p>

<p><em>EDIT: Some other answers have suggested using <code>while B not in "yYnN"</code> or equivalents. This works here because all of your expected responses are one character. If you decide later to accept <code>"yes"</code> as a response, then you will have to use a list like I have shown above.</em></p>

python while-loop