0

If 2 of 3 Values are True then Print true, if not Print false.

output = ""
w1 = input() 
w2 = input() 
w3 = input() 

output = w1 and w2 or w1 and w3 or w2 and w3

print(output)

I dont understand why this code prints False when w1 and w3 are true.

This is working but i dont understand the deference

output = ""
w1 = not input() == "False"
w2 = not input() == "False"
w3 = not input() == "False"

output = w1 and w2 or w1 and w3 or w2 and w3

print(output)
LCyclix
  • 23
  • 2
  • 6
    The string `"False"` will not evaluate falsey, the only string that evaluates falsey is the empty string `''`. – Cory Kramer Oct 28 '21 at 12:34
  • 3
    `input` returns a string. A string is only *falsey* when it's empty. Any other string is *truthy*. `"False"` is *truthy*. – deceze Oct 28 '21 at 12:34
  • 2
    `from collections import Counter` `output = Counter([w1, w2, w3])['True'] >= 2`… – deceze Oct 28 '21 at 12:35
  • 3
    Also, you should do `input() != 'False'` instead of negating a positive comparison… – deceze Oct 28 '21 at 12:36
  • 2
    `[w1, w2, w3].count(True) == 2` – Maroun Oct 28 '21 at 12:37
  • Does this answer your question? [How to test multiple variables against a single value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-single-value) – 0x5453 Oct 28 '21 at 12:38

2 Answers2

0

Try this one. In this case, w1,w2,w3 will be Boolean.

w1= input() =='True'
w2= input() =='True'
w3= input() =='True'

output = ((w1 and w2) or (w1 and w3) or (w2 and w3)) and (not (w1 and w2 and w3))

print(output)
AziMez
  • 2,014
  • 1
  • 6
  • 16
0

In case you want to have True output, when exactly 2 of the 3 variables are "True" (so all 3 variables being "True" will result in False), use:

w1 = 1 if input() == "True" else 0
w2 = 1 if input() == "True" else 0
w3 = 1 if input() == "True" else 0

output = True if w1 + w2 + w3 == 2 else False
Mahrkeenerh
  • 1,104
  • 1
  • 9
  • 25