用python求解鸡兔同笼

head,foot = input("请输入头和脚的数目(用逗号分隔):").split(",")
h = eval(head)
f = eval(foot)
c = ()
r = ()
for i in range(h+1):
    for j in range(h+1):
        if i*2+j*4 == f:
            c = i
            r = j
            break
print("鸡的数目为{}兔子的数目为{}".format(c, r))

你可能感兴趣的:(python学习笔记,python)