1 Star 0 Fork 0

wdc/Python001

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
chicks_n_rabs.py 565 Bytes
一键复制 编辑 原始数据 按行查看 历史
BhavKaran 提交于 2018-10-11 17:41 . 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)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ijiwei/Python001.git
git@gitee.com:ijiwei/Python001.git
ijiwei
Python001
Python001
master

搜索帮助