python--Selling Goldfish problems

Source: Internet
Author: User

Example: Xiao Ming transfer Pension a pot of goldfish 5 times for sale: The 1th time sell all the half plus 1/2, the 2nd time to sell the remaining One-third plus 1/3, 3rd sell the remaining One-fourth plus 1/4;
Sell the remaining one-fifth plus 1/5 for the 4th time, and finally sell the remaining 11. Q. How many fish are there in the original tank? The answer is 59.

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3n = 114 whileTrue:5x =N6 forIinchRange (2, 5+1):7× = x (x/i+1/i)8 ifx = = 11:9 Print(n)Ten ##### Onex =N A forIinchRange (2, 5+1): -m = x/i+1/I -x = x-m the Print('%d:mai-->%d shend-->%d'% (i-1, M, x)) - ##### - Break -n = n + 1


Execution Result:
1:mai-->30 shend-->29
2:mai-->10 shend-->19
3:mai-->5 shend-->14
4:mai-->3 shend-->11


python--Selling Goldfish questions

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.