**Python code to find bugs (2) **
**Code design requirements of the previous period: **
There are four numbers: 1, 2, 3, 4. How many different three-digit numbers can be formed without repeated numbers? What is each?
Please read the code carefully to find out the bugs!
**Answer: ** There are 5 bugs in total. (Quickly check your own answer, are they all right?)
(1) The range parameter of the three for loop iterations should be (1,5), so that it can loop 1-4 times;
(2) The condition of if( i != k && i != j && j != k) is a parallel relationship. It should be an AND operation. Use the and keyword. The correct writing is: if( i != k and i! = j and j != k). There is a habit of using &&, which is probably a C language?
(3) Why is there no colon after the If statement? Haha, is it because your hands are soft and you have no energy to write?
(4) The print method is bracketed after Python3.
(5) Finally, there is an invisible bug, that is, the print statement is a clause of the if statement, so it must be indented. Brother, if there is no indentation like now, wouldn't the if statement be useless? The result will be that all loop results will be printed. Is that a bit embarrassing? !
So, the correct code should look like this:
Huh! It seems that the difference is not very big~.
Yes! If the bug is big, is it still called a bug? Maybe it should be called an elephant.
Having said that, if the code problem really looks like an elephant, a behemoth, should I still find it?
Regarding the issue of program bugs, I would like to give you a word: don't do evil for small things, don't do good for small things! Just kidding, it's not so serious.
Today’s question is announced below.
**Code design requirements for this issue: **
The bonus issued by the enterprise is based on the profit commission. The payment standard is profit:
(1) When it is less than or equal to 100,000 yuan, the bonus can be increased by 10%;
(2) When 100,000 to 200,000 yuan, the portion above 100,000 yuan can be commissioned at 7.5%;
(3) When 200,000-400,000, the portion above 200,000 yuan can be commissioned at 5%;
(4) 400,000-600,000, the part higher than 400,000 yuan can be commissioned 3%;
(5) When 600,000-1,000,000, the part higher than 600,000 yuan can be commissioned 1.5%,
(6) When it is higher than 1 million, the portion exceeding 1 million is 1% commission.
Requirement: Enter the profit of the month from the keyboard to calculate the total amount of bonuses that should be paid?
code show as below:
In fact, we talked about this case in "Introduction to Python". Because it is an introductory course, we use a more intuitive and easy-to-understand method on the solution, and the code may be easier to understand.
The code here may be a little abstract. Its value lies in that it stores the two sets of data of each evaluation section of the profit and the bonus percentage ratio in two different lists, but they have the same length. And the corresponding relationship. This is a model of applying the list data structure to solve problems. Every line of code is a classic and it is worth learning.
**However, there are still some small bugs in the above code. Keep your eyes open and look carefully! **
If you find it, just write it in the message so that we can check the answer together tomorrow.
I found that most of our readers are shy and don't like to leave comments. However, the higher the level of participation, the more fun you will have in learning and the better the learning effect. Why not?
**Well, wait for the answer to be announced tomorrow. **
Reminder: Conventionally, all codes are based on Pythpn3.
Recommended Posts