How to guess numbers by Python
Today, I would like to share with you the relevant knowledge of how to guess numbers in Python. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
First, guess the numbers
How many three digits with different and non-repeating numbers can be made up of 1 to 4? What are the differences?
Analysis: the numbers that can be filled in 100 digits, ten digits and individual digits are 1, 2, 3 and 4. Make up all the permutations and then remove the ones that don't meet the conditions.
Second, the calculation of the bonus paid by the company
Analysis: please use the number axis to demarcate and locate. Note that the bonus should be defined as a growth integer.
Program source code:
3. An integer plus 100 is a complete square, and plus 168 is a complete square. What is the number?
Analysis:
Program source code:
4. Enter * year * month * day to judge which day of the year it is?
Analysis: take March 5 as an example, first add up the previous two months, plus 5 days is the day of this year, in special cases leap years and input months greater than 2 need to consider an additional day:
Program source code:
The output result of the above example is:
Enter three integers x _ rem _ y _ Z and output these three numbers from small to large.
Analysis: we put the minimum number on x, first compare x with y, if x > y, exchange the values of x and y, then compare x with z, and exchange the values of x and z when x > z, so that x can be minimized.
Program source code:
VI. Fibonacci series
Analysis: Fibonacci series (Fibonacci sequence), also known as golden section series, refers to such a series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ….
Mathematically, the Fibonacci sequence is defined by recursion:
Program source code:
Method one
Method 2:
The above example outputs the 10th Fibonacci series, and the result is: 55
Method 3:
The running output of the above program is as follows:
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
7. Copy the data from one list to another:
Program analysis: using list [:]
Program source code:
The output result of the above example is:
[1, 2, 3]
8. Output 9: 9 multiplication table
Analysis: branch and column consideration, a total of 9 rows and 9 columns, I control rows, j control columns.
Source code:
The output result of the above example is:
These are all the contents of the article "how to guess numbers in Python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.