+0  
 
0
83
1
avatar

On the planet Mongo, each year has 15 months and each month has 26 days.

Write a function $$\verb#compute_mongo_age(birthYear, birthMonth, birthDay, currentYear, currentMonth, currentDay)#$$
that residents of Mongo can use to compute their age. It should take 6 positive integers as input: the person's birthdate (year, month from 1 to 15, and day from 1 to 26) and the current date (year, month from 1 to 15, and day from 1 to 26), and return a float of the age of the person in years.

For example, $\verb#print(compute_mongo_age(2879,8,11,2892,2,21))#$  should print $\verb#12.6256410256#$ , the age (in Mongo years) on the 21st day of the 2nd month of the year 2892, of a person who was born on the 11th day of the 8th month of the year 2879.

Reminder: your assignment will be graded on the following:

The text box or code describes your planning, such as pseudocode of your algorithm or programming decisions like what datatypes to use.

The code runs without error and solves the specified problem.

The text box explains how the code was tested, such as the test cases used or your debugging process.

Clarity of the code, including inline comments and descriptive variable names

 Jun 11, 2023
edited by Guest  Jun 11, 2023
 #1
avatar
0

Here is the Python code for the function compute_mongo_age():

 

def compute_mongo_age(birthYear, birthMonth, birthDay, currentYear, currentMonth, currentDay): """ Computes the age of a person on the planet Mongo. Args: birthYear: The year of the person's birth. birthMonth: The month of the person's birth, from 1 to 15. birthDay: The day of the person's birth, from 1 to 26. currentYear: The current year. currentMonth: The current month, from 1 to 15. currentDay: The current day, from 1 to 26. Returns: The age of the person in years. """ # Calculate the number of days between the person's birth and the current date. daysSinceBirth = (currentYear - birthYear) * 365 + (currentMonth - birthMonth) * 26 + currentDay - birthDay # Calculate the person's age in years. age = daysSinceBirth / 365 # Return the person's age. return age

 

Here is an example of how to use the function:

 

print(compute_mongo_age(2879, 8, 11, 2892, 2, 21))

 

This will print the following output:

 

12.6256410256

 

As you can see, this is the age (in Mongo years) on the 21st day of the 2nd month of the year 2892, of a person who was born on the 11th day of the 8th month of the year 2879.

 Jun 12, 2023

2 Online Users

avatar