-1

I'm aiming to check if b / a's answer is divisible by 2, and if it is - it will print yes.

   a = int(input())
   b = int(input())
   if b / a #is divisible by 2
         print("Yes.")
   else:
         print("No.")

3 Answers3

2

How about this?

a = int(input())
b = int(input())
if (b / a) % 2 == 0:
    print("yes")
else:
    print("no")
VisioN
  • 143,310
  • 32
  • 282
  • 281
Daisuke Akagawa
  • 484
  • 2
  • 9
0

Use modulo(%) so for this example if (b/a)%2 == 0:

0

You can also use the ternary operator to combine the if/else statement into a single print statement like this:

print("yes" if (b / a) % 2 == 0 else "no")

You can also do it in a branchless fashion to decrease complexity and increase speed:

print("yes" * ((b/a) % 2 == 0) + "no" * (not (b/a) % 2 == 0))

This works because False has an int value of 0, therefore "text" * False = ""
Similarly, "text" * True = "text"

Alex Mandelias
  • 436
  • 5
  • 10