In [16]:
from IPython.display import *
from sympy import *
var('c p s', integer = True, positive = True)
# There are 20 heads and 56 legs. How many chickens,
# pigs and spiders are there?
for ts in range(4):
  sol = solve((c + p + ts - 20,c * 2 + p * 4 + ts * 8 - 56),(c,p)) \
    or {c:None,p:None}
  sol[s] = ts
  display(sol)
{c: 12, p: 8, s: 0}
{c: 14, p: 5, s: 1}
{c: 16, p: 2, s: 2}
{c: None, p: None, s: 3}