**Python code to find bugs (4) **
**The code design requirements of the previous period: **Please output the 9*9 multiplication formula table.
code show as below:
Please read the code carefully to find out the bugs!
**Correct answer: **There are 3 bugs in total. (The answer time, see how many correct answers?)
(1) First of all, the first for loop is still the parameter problem of range(). Its second parameter represents the number sequence before it (1 less than it), since it is a 9*9 multiplication formula Table, then it should take two numbers from 1-9. Therefore, the range parameter should be (1,10).
(2) The second for loop is still a matter of range parameters. It takes the value from 1 to the one before i. If the maximum value of i is 9, it means the maximum value of the second loop It is 8, and the correct one should be 9. Therefore, the i here should be changed to i+1.
(3) There are always people who are not sensitive to indentation issues. Why? It's still a matter of habit. The print() method code of the third line of code is not indented, the consequences are very serious, and all calculation results cannot be printed out completely.
Interested students can run this code with errors to see what the results are?
The correct code should look like this:
Take a look, the three-line code is very simple. After the modification, does it feel different? (^-^).
**Comment: **The problem of finding bugs yesterday is mainly for everyone to consolidate the application of range() in the for loop. Pay special attention to its parameter value range and the importance of code indentation!
This case has also been discussed in the "Python Introduction" sent in front of the official account of Gaodu's official account or the "Python Easy Introduction" video course on the Gaodu website, but the code details are somewhat different. Interested students can browse and compare to see which code do you like better? !
Today’s question is announced below.
**Code design requirements for this issue: **
Use the nesting of conditional operators to complete this question: students with academic performance >=90 points are represented by A, those with a score of 60-89 are represented by B, and those with a score of less than 60 are represented by C.
Demand analysis: basic expression of conditional operator: (a>b)?a:b
code show as below:
Obviously, this case requires us to use conditional judgment sentences to solve the problem.
It is recommended that you preview the correct grammar of the conditional judgment sentence. Those who have not yet memorized and mastered it can read the "Introduction to Python" published in front of this official account, and the video courses of "Python Easy Introduction" and "Python Web Development" on the Gaodu website. .
https://www.igaodu.cn (Love Gaodu, learn programming, teach you step by step!)
In addition, we must pay special attention to the details of format syntax.
OK, I wish you all happy finding bugs!
If you find it, just write it in the message. We will check the answer together tomorrow.
**The correct answer will be announced tomorrow. **
**Reminder: Conventionally, all codes are based on Pythpn3. **
Recommended Posts