YouTip LogoYouTip

Python Exercise Example28

# Python2.x Python Exercise 28 [![Image 3: Python 100 Examples](#) Python 100 Examples](#) **Question:** Five people are sitting together. How old is the fifth person? He says he is 2 years older than the fourth person. When asked about the fourth person's age, he says he is 2 years older than the third person. When asked about the third person, he says he is 2 years older than the second person. When asked about the second person, he says he is 2 years older than the first person. Finally, when asked about the first person, he says he is 10 years old. How old is the fifth person? **Program Analysis:** Use a recursive method. Recursion is divided into two stages: backward deduction and forward deduction. To know the age of the fifth person, you need to know the age of the fourth person, and so on, deducing backward to the first
← Python Exercise Example29Python Exercise Example27 β†’