0

I'm trying to code if three numbers are even, odd, or neither (when the numbers have an even AND odd in the input). I'm just stuck since every time it outputs "odd" no matter the numbers. Here's my code so far:

msg = input("Enter a,b,c: ")
nums = msg.split(',')

a = int(nums[0])
b = int(nums[1])
c = int(nums[2])

if (a, b, c % 2) == 0:
    print("even")
else:
    print("odd")

my professor mentioned using tuples but I don't know where to incorporate it. Any help is appreciated!

Skencil
  • 5
  • 2
  • Does this answer your question? [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – AMC Oct 18 '20 at 00:35

2 Answers2

1

I think your professor meant something like this:

if (a % 2, b % 2, c % 2) == (0, 0, 0):
Jasmijn
  • 9,370
  • 2
  • 29
  • 43
0

Your condition in if is wrong, because it basically compares tuple to 0 and is always False. Corrected script:

msg = input("Enter a,b,c: ")
nums = msg.split(',')

a = int(nums[0])
b = int(nums[1])
c = int(nums[2])

if a % 2 == 0 and b % 2 == 0 and c % 2 == 0: 
    print("even")
else:
    print("odd")

Or you can use builtin function all():

if all(number % 2 == 0 for number in [a, b, c]):
    print("even")
else:
    print("odd")
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91