Python code to find bugs(9)

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

There are 5 people sitting together and ask how old is the fifth person? He said he was 2 years older than the fourth person. Asked the age of the fourth person, he said that he was 2 years older than the third person. Ask the third person and say that he is two years older than the second person. Ask the second person and say that he is two years older than the first person. Finally, I asked the first person, he said he was 10 years old. How old is the fifth person?

Requires calculation using recursive algorithm.

code show as below:

Please read the code carefully to find out the bugs!

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

(1) The fifth line of code: c = age(n) + 2, the age() function is called. This is the characteristic of the recursive algorithm, but the parameter n represents the age in each round of calculation, so it should be n-1 with each call.

(2) Is the return value of the function surely n? Made the same mistake the last time. Should be modified to return c.

So, the correct code should look like this:

**Comment: **This code finds bugs, is a case of reviewing recursive algorithms, the main purpose:

(1) Consolidate the learning recursive algorithm.

(2) Deepen the understanding of the return value of the function in the recursive algorithm.

For students who have difficulty understanding the above code, please read and study the "Introduction to Python" sent by Gaodu, or the video course "Introduction to Python Easy" on the Gaodu website.

**Code design requirements for this issue: **

Two matrices with 3 rows and 3 columns:

X = [[12,7,3],

[4 ,5,6],

[7 ,8,9]]

Y = [[5,8,1],

[6,7,3],

[4,5,9]]

Please add the data at the corresponding positions and return a new matrix.

code show as below:

Of course, the above code is still buggy. Please find out, post in the message, and have the answer tomorrow.

**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(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
Python SMS bombing code
Centos default python2.6 upgrade to
Solution to python alignment error
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
Introduction to Python related modules
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| 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
How to save the python program
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
How to filter numbers in python