This article brings you relevant knowledge about python. It mainly summarizes and introduces some classic cases. I hope everyone can learn it and it can be helpful to everyone.
Recommended learning: python tutorial
Today I have collected several classic Python cases for you, I hope you can learn it!
1. Guess the numbers
How many different three-digit numbers can be formed from 1 to 4 without repeating numbers? What are the differences?
Analysis: The numbers that can be filled in the hundreds, tens, and ones places are all 1, 2, 3, and 4. After composing all the permutations, remove the permutations that do not meet the conditions.
## 2. Calculation of bonuses issued by the company
Analysis:
Program source code:
Analysis: Take March 5th as an example, first add up the previous two months, and add 5 days to get the day of the year. In special cases, it is a leap year and the input month is greater than 2 You need to consider adding an extra day:
Program source code:
The output result of the above example is:
Analysis: We put the minimum number on x, first put x Compare with y, if x>y, exchange the values of x and y, and then compare x and z. When x>z, exchange the values of x and z, so that x can be minimized.
Program source code:
##6. Fibonacci Sequence
Analysis: Fibonacci sequence, also known as the golden section sequence, refers to such a sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,… .
In mathematics, the Fibonacci sequence is defined by a recursive method:Program source code:
Method 2:
The above example outputs the 10th Fibonacci sequence, and the result is: 55
The output result of the above program is:
7. Copy data from one list to another list:
Program analysis: use list[:]
Program source code:The output result of the above example is:
8. Output 9*9 multiplication table
Analysis: consider rows and columns, a total of 9 rows and 9 columns, i controls the rows and j controls the columns.
Source code:
The above is the detailed content of Detailed explanation of classic techniques in Python cases. For more information, please follow other related articles on the PHP Chinese website!