Ask Question
19 July, 11:44

Create a Python program by defining a function that calculates the year of birth of a person whose age is known to you. (You may use an input statement to ask the user to enter their age).

+1
Answers (1)
  1. 19 July, 13:10
    0
    import datetime def get_year_of_birth () : age = int (input ("Enter your age: ")) current_year = datetime. datetime. now (). year year_of_birth = current_year - age return year_of_birth print (get_year_of_birth ())

    Explanation:

    Firstly, we import datetime module as we need it to get the current year (Line 1).

    Next, create a function named it as get_year_of_birth (Line 3). Prompt user to input age and assign it to a variable (Line 4). Next, we use now () method from datetime module to get the current date and time and extract the year component (Line 5). At last, calculate the year of birth by subtracting the current_year with age and return it as output (Line 6-7).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Create a Python program by defining a function that calculates the year of birth of a person whose age is known to you. (You may use an ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers