Python code to find bugs(5)

**Python code to find bugs (5) **
**Code design requirements of the previous period: **

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.

code show as below:

Please read the code carefully to find out the bugs!

**Correct answer: **There are 3 bugs in total. (For the answer time, see how many answers are correct?)

(1) The return value of the input() method is a string, which requires forced type conversion to participate in the calculation. This is not the first time I have encountered it, haha, it depends on if anyone has a memory.

(2) grade = A / B / C, where A, B, and C are all strings and should be enclosed in quotation marks. Otherwise, what they are like now? ... is an undefined variable and cannot be assigned to another variable.

(3) There is another magical error: how does else if look so familiar? That's right, it's written in many languages, here...Is your hand slippery, haha! Python is very simple, just need elif.

So, the correct code should look like this:

Well, this one looks more "pure"!

**Comment: **The main purpose of finding bugs yesterday:

(1) Let everyone consolidate the use of input () return value.

(2) Pay attention to the standard use of character strings.

(3) Pay attention to the standard use of conditional judgment sentences.

For students who have a vague understanding of the above knowledge points, please read and study the "Introduction to Python" sent outside of the Gaodu Express, or the video course "Introduction to Python Easy" on the Gaodu website.

Today’s question is announced below.

**Code design requirements for this issue: **

A ball falls freely from a height of 100 meters, and rebounds back to half of its original height each time it hits the ground. When it falls again, how many meters does it pass when it hits the ground for the tenth time? How high is the 10th rebound?

Demand analysis: This is a common mathematical problem. See how to solve it by programming?

code show as below:

Have you noticed? This code is very interesting!

The loop statement must be used. If you use the cumulative sum method, you can directly obtain the number of meters the ball has passed during the Nth landing. The cumulative half (divided by 2) calculation can also directly obtain the final rebound height.

But, why define two lists?

I recently talked to a friend about Python and discovered this interesting feature. Many friends who write Python code have such a habit. It is natural for everyone to record the behavior of a repetitive sequence in a list of data. Then, you Which item in it is needed, it is convenient for you at any time.

Rather than our usual practice, through loops, the code directly obtains the final desired result after the calculation, and ignores the intermediate state data.

I feel that these are two different thinking habits. I guess, is it related to Python's genes? !

Well, the problem is that this beautiful code is still a bit flawed, where is the **bug? **

Find it out, post it in the message, and have the answer tomorrow.

For students who cannot find a bug, it is recommended to review the "Introduction to Python" published earlier outside the Gaodu number, as well as the "Easy Introduction to Python" and "Python Web Development" video courses on the Gaodu website.

https://www.igaodu.cn (Love Gaodu, learn programming, teach you step by step!)

Reminder, pay special attention to the details of the format grammar.

**The correct answer will be announced tomorrow. **

Reminder: Conventionally, all codes are based on Pythpn3.

Recommended Posts

Python code to find bugs (2)
Python code to find bugs(7)
Python code to find bugs(4)
Python code to find bugs (3)
Python code to find bugs(9)
Python code to find bugs(6)
Python code to find bugs (1)
Python code to find bugs(8)
Python code to find bugs(5)
Actually very simple | Python code to find bugs (12)
Minimalism is the soul of Python | Python code to find bugs (10)
How to comment python code
python how to view webpage code
How to wrap in python code
Python handles operation code to execl
01. Introduction to Python
200 lines of Python code to achieve snake
Python Romberg method to find integral examples
Does Python code need to be indented
Introduction to Python
How to use code running assistant in python
500 lines of python code to achieve aircraft war
How to set code auto prompt in python
Python how to move the code collectively right
Centos 6.4 python 2.6 upgrade to 2.7
Centos 6.4 python 2.6 upgrade to 2.7
Python SMS bombing code
Solution to python alignment error
CentOS upgrade python2 to pyth
How to write Pythonic code
Python drawing rose implementation code
How to find the area of a circle in python
How to learn python quickly
How to uninstall python plugin
Python regular expression example code
Find the kernel source code corresponding to the running Ubuntu version
Python implements code block folding
Python install OpenCV sample code
3 ways to encrypt Python files
Python implements verification code recognition
How to understand python objects
How to use python tuples
Is python code case sensitive
Python telnet login function implementation code
Python| function using recursion to solve
Method steps to increase python font
How to use python thread pool
Use python to query Oracle database
Use C++ to write Python3 extensions
How to write python configuration file
Python novice learns to raise usage
Use python to achieve stepwise regression
Python is a cross-platform language code
Python ATM function implementation code example
Python implements 126 mailboxes to send mail
Using Python to implement multiple clipboards
How to omit parentheses in Python
How to install Python 3.8 on CentOS 8
Python example to calculate IV value
How to install Python 3.8 on Ubuntu 18.04
How to write classes in python