**Python code to find bugs (3) **
**Code design requirements of the previous period: **
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:
Please read the code carefully to find out the bugs!
**Answer: ** There are 5 bugs in total. (Right answer time, how many correct answers?)
(1) First, the data obtained by the input() method is of string type by default, and it needs to be converted to integer type to participate in the calculation;
(2) A semicolon should not be added at the end of the statement. This is one of the characteristics of Python. Look at what is after y = 0?
(3) If the condition after the If statement is an independent logical (judgment) operation, there is no need for parentheses. Second, third,
(4) There should be a colon at the end of the If statement, so forgetting is really great.
(5) Hey, what the hell is the {...} after the if statement? Was it written in C/C++ accidentally? Don’t remember that Python code blocks don’t need messy parentheses? Wouldn't it look more concise and comfortable to remove the parentheses?
So, the correct code should look like this:
Huh! It really looks refreshed~. Alright, everyone, please raise your hands if you get all the correct answers! (^-^).
Haha, to be honest with you, from this case, if you really just found a few bugs, that would be a shame! The most important value of this code is the ability to abstract data and use data structure flexibly.
Because of the use of two list data, the idea changed, and the code suddenly became much simpler. This method is particularly in line with the minimalist style of Python, so students who do not fully understand it must savor it carefully.
If you don't know the reason, please refer to the "Getting Started with Python" or the video course of "Getting Started with Python Easy" sent by the official account or the video course of "Getting Started with Python Easy".
Today’s question is announced below.
**Code design requirements for this issue: **Please output 9*9 multiplication formula table.
code show as below:
In fact, we have also talked about this case in "Introduction to Python". Students who are particularly careful must have noticed that this code is different from the previous code.
The code here may be more concise, and its value is still in cultivating our ability to think abstractly. Please savor the beauty in it.
**Yes, there are still some small bugs in the above code. Keep your eyes open and keep looking! **
If you find it, write it in the message so that we can check the answer together tomorrow. (Everyone really needs to cultivate the habit of leaving messages~)
**The correct answer will be announced tomorrow. **
**Reminder: Conventionally, all codes are based on Pythpn3. **
Recommended Posts