#Need help with age in months

25 messages · Page 1 of 1 (latest)

vivid edge
#

I'm trying to calculate age in months the answer is supposed to be 481 but I keep getting 487. I'm very close but I'm unsure of the mistake I'm making in the calculation. Any help would be appreciated thank you for your time! I have been doing this for two hours but like I might be asking a stupid question.

My code for the calculation of age in months:

current_date = (current_year * 365) + (current_month * 30)
birth_date = (birth_year * 365) + (birth_month * 30)
age_in_month = (current_date - birth_date)//30

print("Age in months:" + str(age_in_month))

autumn cloak
#

What values are you using to test your code?

vivid edge
#

2020, 8, 1980, 7

autumn cloak
#

Where did you get 481 from?

vivid edge
#

That was the answer for the example that was given to me

autumn cloak
#

Wait

#

If you want to calculate the months, why do you convert everything into days before converting to months?

#

(2020-1980) / 12 + (8-7) is 481 as desired

vivid edge
autumn cloak
vivid edge
#

Damnnn was I just overthinking it?

#

Thank you so much gonna try it out

autumn cloak
vivid edge
#

Oh I just tried it and I got 4.333repeating4

#

My full code

autumn cloak
#

Oh apologies

#

It's * 12 not / 12

#

12 months in a year

vivid edge
#

Ahh that makes sense

#

OMG

#

Wow it worked

#

Thank you so much! I appreciate it

#

Well now I learned how to calculate age in months properly

autumn cloak
#

Haha nice!