---
But... now let's think for a moment about what you're doing there. Not the technical bits, but what the user sees.
You have decided that the average male lives to 71-72 and female to around 74. You have then decided that this average should be taken as a hard, fixed limit. And that people will die at that age no matter what.
These two assumptions are somewhat tricky. I mean, the first one is fairly random without a context. For, say, India, this is about right, but for other countries of the world -or as an average for the whole world- it can be quite different. And you don't mention any particular country.
But anyway, it's the second assumption that is more problematic. Because the number is just an average and using it as a hard limit is clearly wrong. First of all because death is not linear. Take a look at this sample table for the US [0]. Life expectancy increases with age. That means that initial life expectancy can be 80 years, but if you make it to 60, your total life expectancy goes up to 84. And if you make it to those 80 your life expectancy still gives you -on average- another 9.5 years to live.
Why is this relevant? Well, because such a calculator would assume the user, the person that goes there to see how much time they have left with their parents... well, still has their parents alive. It would be stupid otherwise if they know their parents are already dead. So this is 2026. The user states that their dad was born in, say, 1956. That's 70 years. Is the 71.5 average life expectancy right? Not at all. Even as an average, even as a hard limit, it is wrong. For a person at 70, that life expectancy would be something like 80+ and the remaining time should be calculated according to that. Sure, this means you need to write code that is a bit more complicated than what you've done here. Because you don't just have one average life expectancy, you need a whole table or function to calculate it. But, hey, this is learning! It's a coding exercise. So it is an opportunity to learn more and go beyond the simple tutorial into an exercise that is just a little bit more advanced.
---
But then again, let's ignore even this. Let's go back and keep the simple exercise. Let's assume just one fixed life expectancy. Then, as I mentioned above, we have a problem that's worse, more... stupid. Because as I said such a calculator has to assume the parents are still alive. Otherwise is simply makes no sense. And yet, you're giving the user the option to choose birth years as far back as 1940, while directly assuming that anyone born before 1952 for men or 1955 for women is already dead.
When you offer that option, you're saying it is a valid option. But when the user chooses it, you're saying they are stupid for doing so.
What you're doing is like this conversation:
- Hi, I visit my dad every Friday afternoon.
- That's nice. But from this other perspective that may not be a lot of time. How old is he?
- Oh, my dad is 78.
- Bad news: your dad's already dead.
- What? No, he's fine, I saw him just yesterday.
- Your dad's been dead for years.
- You're an asshole.
---So... again, congratulations on your coding exercise. You did it. The coding is solved [perhaps]. Well done.
But take this as an additional learning point: The problems you solve will sometimes involve writing code, but they will always require you to think about the details and nuances of the problem itself. It's all about the decisions and assumptions you make.