Your code returns None if a != b
Since you have a return inside the while loop, if the while loop never executes, Python returns the default value of None , which cannot be assigned to new_A, new_B .
>>> print make_them_different(2, 3) None >>> print make_them_different(2, 2) (2, 1)
You can fix this by returning the default values ββ(since they are different and what you intend to do)
def make_them_different(a,b): while a == b: a = randint(1,3) b = randint(1,3) return (a,b)
Demo -
>>> make_them_different(2, 2) (3, 2) >>> make_them_different(2, 3) (2, 3)
source share