15 Python small case, do not know how much you will!
First, guess the number
1 to 4 How many three digits of a distinct and non-repeating number can be formed? What's the difference?
Analysis: Can be filled in hundreds, 10 digits, single digit numbers are 1, 2, 3, 4. Make all the permutations and then remove the permutations that do not meet the criteria.
Program Source code:
Second, the calculation of bonuses issued by the company
Analysis: Please use the axis to demarcation, positioning. Note that the bonus definition should be defined as the growth integral type.
Program Source code:
A city integer plus 100 is a complete square number, plus 168 is a complete square number, what is the number?
Analysis:
Program Source code:
Iv. Enter * YEAR * month * day to determine if this day is the first of the year?
Analysis: Take March 5 as an example, the first two months to add together, plus 5 days is the first day of this year, special cases leap years and enter the month greater than 2 o'clock to consider adding a day:
Program Source code:
The result of the above example output is:
Enter three integers x, y, Z, and turn these three numbers from small to large output
Analysis: We put the minimum number on X, first compare x with Y, if x>y the value of x and Y, and then compare X with Z, when x>z the value of x and z, so that x is the smallest.
Program Source code:
Vi. Fibonacci Sequence
Analysis: Fibonacci sequence (Fibonacci sequence), also known as the Golden Section, refers to a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 、......。
Mathematically, the faipot sequence is defined in a recursive way:
Program Source code:
Method One
Method Two
The above example outputs a 10th Fibonacci sequence with the result:
55
Method Three
The above program run output is:
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
Seven. Copy data from one list to another list
Program Analysis: Use list [:]
Program Source code:
The result of the above example output is:
[1, 2, 3]
Eight, output 9*9 multiplication table
Analysis: Branch and column considerations, a total of 9 rows of 9 columns, I control row, J control column.
Source:
The result of the above example output is:
Nine, pause one second output
Analysis: Using the Sleep () function of the time module
Program Source code:
The above example output is (there will be a pause effect):
2 B
1 A
Ten, pause the output for one second, and format the current time
Source:
The result of the above example output is:
2015-10-21 17:48:40
2015-10-21 17:48:41
Xi, there are a pair of rabbits, from the 3rd month after birth a pair of rabbits each month, the small rabbit to the third month after the birth of a pair of rabbits each month, if the rabbit is not dead, ask the total number of rabbits each month?
Program Analysis: The law of Rabbits for the series 1,1,2,3,5,8,13,21 ....
Program Source code:
The result of the above example output is:
12, determine how many primes between 101-200, and output all prime numbers
Analysis: The method of judging primes: to remove 2 to sqrt (this number) with a number, if divisible, indicates that the number is not a prime, and vice versa is a prime.
Code:
The result of the above example output is:
13, print out all the "Narcissus number"
Program Source code:
The result of the above example output is:
153
370
371
407
14, the decomposition of a positive integer factorization
Program Source code:
The result of the above example output is:
90 = 2 * 3 * 3 * 5
100 = 2 * 2 * 5 * 5
Using nesting of conditional operators to complete learning achievement calculation
The students of the study score >=90 with a, 60-89 points between the use of B, 60 points below the C expression.
Analysis: (a>b)? A:b This is a basic example of conditional operators.
Code:
The result of the above example output is:
Enter Score:
89
89 belongs to B
How do the little friends learn? Welcome Message Comments!
15 Python small case, learn these, Python Foundation has passed!