Home  >  Article  >  Backend Development  >  Detailed explanation of classic techniques in Python cases

Detailed explanation of classic techniques in Python cases

WBOY
WBOYforward
2022-03-08 17:38:493146browse

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.

Detailed explanation of classic techniques in Python cases

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: Please use the number axis to divide and position. Note that the bonus needs to be defined as an integer when defining.

Program source code:

##3. An integer plus 100 is a perfect square number , plus 168 is another perfect square number. What is this number?

Analysis:

Program source code:

4. Enter *year*month*day and determine what day of the year this day is?

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:

5. Input three integers x, y, z, and output these three numbers from small to large

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 1

Method 2:

The above example outputs the 10th Fibonacci sequence, and the result is: 55

Method 3:

The output result of the above program is:

[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

7. Copy data from one list to another list:

Program analysis: use list[:]

Program source code:

The output result of the above example is:

[1, 2, 3]

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 output result of the above example is:

Recommended learning:

pythontutorial

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete