Why isnt my code working

I am trying to make a heads/tails simulator for class and its supposed to say when the two match.

import random
a = random.random()
b = random.random()
if a <= .5:
    print("heads")
else:
    print("tails")
if b <= .5:
    print("heads")
else:
    print("tails")
if a and b < 0.5 or a and b > 0.5:
    print("match")
else:
    print("no match")

this comparison isn’t any good:

if a and b < 0.5 or a and b > 0.5:

just like with math, python knows order of operations. the and keyword is resolved first. Furthermore, you don’t compare a with anything, so python will just check if a variable is truthy.

Whats the best way to fix it?

you want to check both a and b are lesser then .5, that for starters.

furthermore, you want to manually evaluate the order of operations, so you can insert brackets where needed to make your condition correct