The problem is that you're using i in both loops. Just swap i for something else in the HCF part, and the infinite loop will work fine.
for x in range(1, smaller + 1): if a % x == 0 and b % x == 0: hcf = x