Python

Age Reverses

 

10 points

If a mother is 27 years old when her child is born, 14 years later she'll be 41 and her child will be 14. These two ages are "reverses." Another example of "reverses": "abc" and "cba." This program looks at when a mother's age and her child's age are reverses. For a given age difference between mother and child, the program figures out if there will be any years when their ages will be reverses. If there are such ages, the program can print them out and count them.

 

Video

The video below shows a completed program being run.

 

Starting Point

Download Reverses.py as a starting point for the project. The file guides you towards completing the program.

 

Extra Credit

3 points

For extra credit, write the function compareReverses(). This function considers every mother/child age combination (up to a mother's age of 99) for every mother/child age difference, from 18 to 49 years. It prints out how many reverses exist for each age difference.

The video below shows the extra-credit code being run.

 

The idea for this program came from Python Programming: An Introduction to Computer Science, Second Edition by John Zelle.