s=smtplib.SMTP('localhost')
s.sendmail(FROM, TO, "the answer is %s" % x) # here is the change
Вы забыли форматер% s в вашей строке!
Итак:
x = 'hello world'
s.sendmail(FROM, TO, "the answer is x")
Выход: the answer is x
А:
x = 'hello world'
s.sendmail(FROM, TO, "the answer is %s" % x)
Выход: the answer is hello world