-2

I am learning python and struggling with this so please help. out of 4 different user input integers, I want to print 'False' if there's a single odd or an even integer in the list. say if user inputs 1,1,2,2, = true... but 1,1,1,2, or 1,2,2,2 = false

my attempt was to check if only one in the list divisible by two (or not) to return false.

a = int(input())
b = int(input())
c = int(input())
d = int(input())

if a or b or c or d % 2 == 0:
    print ('FALSE')
elif a or b or c or d % 2 != 0:
    print('FALSE')
else:
    print('TRUE')

please help a guide to clean my mess or understanding .. thank you!

Kaka Pin
  • 81
  • 1
  • 9

1 Answers1

0

You're effectively testing whether there's an odd number of evens among four numbers. If there's an odd number of evens, then the sum of the four values will be odd. You can therefore check the sum as following:

a = int(input())
b = int(input())
c = int(input())
d = int(input())

if (a + b + c + d) % 2 == 0:
    print ('TRUE')
else:
    print('FALSE')
Artem Sokolov
  • 13,196
  • 4
  • 43
  • 74
sam1064max
  • 55
  • 6