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.")
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.")
How about this?
a = int(input())
b = int(input())
if (b / a) % 2 == 0:
print("yes")
else:
print("no")
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"