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>The issue is that you are doing <code>while B != "y" or B != "Y" or B != "N" or B != "n":</code></p>

<p>With <code>or</code> it returns true if either of its options are true. So if B="N"
<code>b!="N" or b!=n"</code> is true because b still isn't "n"</p>

<p>You can solve this by replacing all the <code>or</code>s with <code>and</code>s to get this
<code>while B != "y" and B != "Y" and B != "N" and B != "n":</code></p>

python while-loop