Python Statistics peach number (monkey points peach)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.