import datetime
print("##### Welcome to age calculator ######")
birth_year = int(input("Enter your year of birth: \n"))
birth_month = int(input("Enter your month of birth: \n"))
birth_day = int(input("Enter your day of birth: \n"))
current_year = datetime.date.today().year
current_month = datetime.date.today().month
current_day = datetime.date.today().day
age_year = current_year - birth_year
age_month = abs(current_month-birth_month)
age_day = abs(current_day-birth_day)
print("Your exact age is: ", age_year, "Years", age_month, "months and", age_day, "days")
Output should look something like below:
##### Welcome to age calculator ######
Enter your year of birth:
1986
Enter your month of birth:
05
Enter your day of birth:
25
Your exact age is: 34 Years 2 months and 2 days
Simple python program to calculate your age
2 responses to “Simple python program to calculate your age”
-
This simply doesn’t work. you will need to create loops to determine whether a person has crossed a specific month time frame. I just started learning python and created one just was looking for a much more efficient way.
from datetime import datetodays_date = date.today()
print(“Current date: “, todays_date)
print(“Current year:”, todays_date.year)
print(“Current month:”, todays_date.month)
print(“Current day:”, todays_date.day)birth_date = int(input(“Enter The date of your birth:”))
birth_month = int(input(“Enter The month of your birth:”))
birth_Year = int(input(“Enter The year of your birth:”))
#we will create a variable dy that is the age that is determined only by knowing the year of birth
dy = todays_date.year – birth_Year
ldy = dy-1if todays_date.month > birth_month:
print(f”you are {dy} years old”)elif todays_date.month = birth_date:
print(f”you are {dy} years old”)elif todays_date.day < birth_date:
print(f"you are {ldy} years old")LikeLike
-
It’s just a basic code for calculating age. You can always add more to it.
LikeLike
-
Latest posts
-
What is Virtualization-Based Security for Windows Guest Operating Systems
Virtualization-Based Security (VBS) for Windows guest operating systems is a security feature that uses hardware virtualization to create and isolate a secure region of memory from the normal operating system.…
·
-
Export DRS (Distributed Resource Scheduler) rules from a vCenter server using PowerCLI-How to?
To export DRS (Distributed Resource Scheduler) rules from a vCenter server using PowerCLI, you can use the following script. This script will connect to your vCenter server, retrieve the DRS…
·
-
vSphere virtual disk transport modes (VADP) for VM backup
Virtual Disk Transport Methods (VADP) offers interfaces for integration of storage-aware applications, including backup, with efficient access to storage clusters. Backup vendors may use different transport methods, which provide efficient…
·
Get updates
Spam-free subscription, we guarantee. This is just a friendly ping when new content is out.

Leave a reply to Aditya Batra Cancel reply