Weeks not in the XXQQ group, see a Python interview question, see which is the monkey, is also a peach, very much like; I also write a Python statistics peach.
#!/usr/bin/env python# -*- coding:utf-8 -*-' title: A pile of peaches is the public property of 7 monkeys, which are evenly distributed. The first monkey came, left and so on to wait until the other monkeys to come, they had to do the peach are divided into 7 parts, found that more than 1. It felt that he had worked hard, and would have eaten more than 1 peaches, and took 7 copies of his 1 parts. The second monkey came, it does not know what happened before, thought the peach has not been divided, so the peach is divided into 7 parts, or more than 1, it eats more than 1 peaches, and take their own 1 to go, and so on, each monkey alone will be the rest of the whole pile of peaches into 7 parts, are more than 1, Will eat the extra 1 peaches and take away their share. Please write a function to find the total number of peaches. "' Def tz (): #初始桃子的个数: 7*7 sum1 = 7*7 flag = 1 while ( flag == 1): count = 0 index = 0 sum2 = sum1 while (count < 7): if ( sum2 % 7 == 1 ): sum2 -= 1 sum2 -= sum2/7 index += 1 if index == 7: print "Total of minimum peaches:%d" % (SUM1) flag = 0 break count += 1 sum1 += 1if __name__ == "__main__": tz ()
This article is from the "no words in the low-key" blog, please be sure to keep this source http://8697623.blog.51cto.com/281874/1786683
Python Statistics peach number (monkey points peach)