Python 五人分鱼
时间: 2023-12-05 10:38:47 浏览: 198
python小工具-摸鱼神器-小说阅读器
以下是两种Python解决五人分鱼问题的方法:
方法一:
```python
fish = 1
while True:
total = fish
enough = True
for i in range(5):
if (total - 1) % 5 == 0:
total = (total - 1) // 5 * 4
else:
enough = False
break
if enough:
print("至少有%d条鱼。" % fish)
break
fish += 1
```
方法二:
```python
def five_fish(n, m):
if n == 1:
return m
else:
return five_fish(n - 1, m) / 0.8 + 1
x = int(input("一共有几人分鱼?"))
y = x + 1
while five_fish(x, y) != int(five_fish(x, y)):
y += x
print("那么至少有%d条鱼。" % five_fish(x, y))
```
阅读全文