Flipping one digit to get all digits the same: is the code wrong?
<p>Trying to solve the following problem:</p>

<p>Given a binary D containing only digits 0's and 1's, I have to determine if all the digits could be made the same, by flipping only one digit. </p>

<p>The input is the number of Ds to test, and then the Ds, one per line. for instance:</p>

<pre><code>3
11111001111010
110
100000000000000
</code></pre>

<p>The output is "Yes" or "No", namely in this instance, the run will look like:</p>

<pre><code>$ python3 first.py
3
11111001111010
NO
110
YES
100000000000000
YES
</code></pre>

<p>However, the automatic evaluator of this problem judges the following code wrong:</p>

<pre><code>T = int(input())

for i in range(T):
    line = input()
    ones = zeros = 0
    for c in line:
        if int(c) == 1:
            ones += 1
        elif int(c) == 0:
            zeros += 1
        else:
            raise ValueError
        if ones &gt; 1 and zeros &gt; 1:
            print("NO")
            break

    if ones == 1:
        print("YES")
    elif zeros == 1:
        print("YES")
</code></pre>

<p>Can you suggest why?</p>

<p>The solution is rather embarrassing: I outputted the answer as all <em>uppercase</em>, where the expected output is <em>Title case</em>. The following code is accepted:</p>

<pre><code>T = int(input())

for i in range(T):
    line = input()
    ones = zeros = 0
    for c in line:
        if int(c) == 1:
            ones += 1
        elif int(c) == 0:
            zeros += 1
        else:
            raise ValueError
        if ones &gt; 1 and zeros &gt; 1:
            print("No")
            break

    if ones == 1:
        print("Yes")
    elif zeros == 1:
        print("Yes")
    elif ones == 0 or zeros == 0:
        print("No")
</code></pre>

python python-3.x