1 Star 0 Fork 1

jack2583/PythonExamples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
chicks_n_rabs.py 565 Bytes
一键复制 编辑 原始数据 按行查看 历史
BhavKaran 提交于 2018-10-11 20:11 +08:00 . Add files via upload
"""
Author Anurag Kumar(mailto:anuragkumarak95@gmail.com)
Module to solve a classic ancient Chinese puzzle:
We count 35 heads and 94 legs among the chickens and rabbits in a farm.
How many rabbits and how many chickens do we have?
"""
def solve(num_heads, num_legs):
ns = 'No solutions!'
for i in range(num_heads + 1):
j = num_heads - i
if 2 * i + 4 * j == num_legs:
return i, j
return ns, ns
if __name__ == "__main__":
numheads = 35
numlegs = 94
solutions = solve(numheads, numlegs)
print(solutions)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jack2583/pythonExamples.git
git@gitee.com:jack2583/pythonExamples.git
jack2583
pythonExamples
PythonExamples
master

搜索帮助