Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to calculate age of user by birth year? comment calculer age de l'utilisateur avec l'année de naissance?

+3 votes
asked Nov 3, 2021 by treefeather1 (150 points)

2 Answers

0 votes
answered Nov 4, 2021 by Peter Minarik (86,200 points)
from datetime import date

now = date.today()
birthDay = date(2000, 3, 14)
delta = now - birthDay
print('birt day: ', birthDay)
print('now: ', now)
print('age: ', delta.days // 365) # integral division (ignoring the fraction part)
0 votes
answered Nov 5, 2021 by Mohul Chakraborty (140 points)
Python

birthYear = int(input("Enter your birth year: "))
#Current year may vary so it is called inside the input function
currentYear = int(input("Enter current year: "))
age = currentYear-birthYear
print("Age is: ",age,"years")

Java

import java.util.Scanner;

public class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter your birth year: ");
        int birthYear = sc.nextInt();
         System.out.println("Enter the current year: ");
        int currentYear = sc.nextInt();
        int age = currentYear-birthYear;
        System.out.println("Age is: "+age+" years");
    }
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...