Python Practice Example 80

Python 100例Python 100 Examples

Question:There is a pile of peaches on the beach, to be divided among five monkeys. The first monkey divided the pile into five equal parts, with one left over. The monkey threw the extra one into the sea and took one share. The second monkey divided the remaining peaches into five equal parts, again with one left over. It likewise threw the extra one into the sea and took one share. The third, fourth, and fifth monkeys all did the same. How many peaches were there at least on the beach originally?

Program analysis:None.

Example (Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': i = 0 j = 1 x = 0 while (i < 5) : x = 4 * j for i in range(0,5) : if(x%4 != 0) : break else : i += 1 x = (x/4) * 5 +1 j += 1 print x

The output of the above example is:

3121

Python 100例Python 100 Examples

Other extensions