# python3.6
from sympy import *
def solute_function():
'''
鸡兔同笼,设鸡x,兔y,则有如下方程:
x+y=head
2x+4y=feet
:return:None
'''
x = Symbol('x')
y = Symbol('y')
in_string = input("请输入头和脚的个数,以空格分离:").split()
a, b = map(int, in_string)
solution = solve([x + y - a, 2 * x + 4 * y - b], [x, y])
x = int(solution[x])
y = int(solution[y])
if x >= 0 and y >= 0 and (x + y) == a:
print("鸡:{}只,兔:{}只。".format(x, y))
else:
print("无解")
这是函数,自己调用就行。如果找不到sympy模块,请先安装:
pip install sympy
本回答被网友采纳