Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 80

Python Exercise Example 80

Python 100 Examples Python 100 Examples

**Problem:** There is a pile of peaches on a beach, and five monkeys come to divide them. The first monkey divides the pile into five equal parts with one left over; it throws the extra peach into the sea and takes one part. The second monkey divides the remaining peaches into five equal parts again, with one left over; it also throws the extra peach into the sea and takes one part. The third, fourth, and fifth monkeys all do the same. What is the minimum number of peaches that were originally on the beach?

**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 Examples Python 100 Examples