Skip to main content

Your Age in Seconds, Minutes, hours and in days program in PYTHON

 

import datetime
print("\nInstructions:")
print("\n1.) Put the date correctly.")


pyear = datetime.datetime.today().strftime ('%Y')
pyear = int(pyear)
pmonth = datetime.datetime.today().strftime ('%m')
pmonth = int(pmonth)
pdate = datetime.datetime.today().strftime ('%d')
pdate = int(pdate)
phour = datetime.datetime.today().strftime ('%H')
phour = int(phour)
pmin = datetime.datetime.today().strftime ('%M')
pmin  = int(pmin)
psec = datetime.datetime.today().strftime('%S')
psec = int(psec)


byear = int(input("Birth year (For eg. 2005, 1976 etc): "))
i = 1
while i>0:
    if byear >= pyear:
        print("\nYear is invalid..")
        byear = int(input("Birth year (For eg. 2005, 1976 etc): "))
        i = i+1
    else:
        break

bmonth = int(input("\nBirth month (For eg. 7, 2, 11, 9 etc): "))
i = 1
while i>0:
    if bmonth>12 or bmonth<1:
        print("\nInvalid Month.")
        bmonth = int(input("Birth month (For eg. 7, 2, 11, 9 etc): "))
        i = i+1
    else:
        break

bdate = int(input("\nBirth date (For eg. 23, 06, 12 etc): "))
i = 1
while i>0:
    if bmonth==1 or bmonth==3 or bmonth==5 or bmonth==7 or bmonth==8 or bmonth==10 or bmonth==12:
        if bdate>31 or bdate<1:
            print("\nInvalid Day.")
            bdate = int(input("Birth date (For eg. 23, 06, 12 etc): "))
            i = i+1
        else:
            break

    elif bmonth==4 or bmonth==6 or bmonth==9 or bmonth==11:
        if bdate>30 or bdate<1:
            print("\nInvalid day.")
            bdate = int(input("Birth date (For eg. 23, 06, 12 etc): "))
            i = i+1
        else:
            break
   
    elif bmonth==2:
        if byear%4==0:
            if bdate>29 or bdate<1:
                print("\nInvalid day.")
                bdate = int(input("Birth date (For eg. 23, 06, 12 etc): "))
                i = i+1
            else:
                break
        elif byear%4!=0:
            if bdate>28 or bdate<1:
                print("\nInvalid day.")
                bdate = int(input("Birth date (For eg. 23, 06, 12 etc): "))
                i = i+1
            else:
                break

bhour = int(input("\nBirth hour (1 - 12): "))
i = 1
while i>0:
    if bhour > 12 or bhour < 1:
        print("The time should be in 1-12 and 12-1 form.")
        bhour = int(input("\nBirth hour (1 - 12): "))
        i = i+1
    else:
        break

bmin = int(input("Birth min (0 - 59): "))
i = 1
while i>0:
    if bmin > 59 or bmin < 0:
        print("minutes should be between 0 - 59")
        bmin = int(input("Birth min (0 - 59): "))
        i = i+1
    else:
        break

bsec = int(input("Birth sec (0 - 59): "))
i = 1
while i>0:
    if bsec > 59 or bsec < 0:
        print("seconds should be between 0 - 59")
        bsec = int(input("Birth sec (0 - 59): "))
        i = i+1
    else:
        break

abc = input("The time provided is in AM or in PM (a/p): ")

if "abc"=="a":
    pass
elif"abc"=="p":
    bhour = 12 + bhour

totalleapyear = 0
for i in range(byear, pyear +1):
  if (0 == i % 4) and (0 != i % 100) or (0 == i % 400):
      totalleapyear = totalleapyear+1

totalsmallyear = pyear - byear - totalleapyear + 1

if(byear%4!=0 and pyear%4!=0):
    totalleap = totalleapyear
elif(byear%4==0 and pyear%4!=0):
    totalleap = totalleapyear - 1
elif(byear%4!=0 and pyear%4==0):
    totalleap = totalleapyear - 1
elif(byear%4!=0 and pyear%4!=0):
    totalleap = totalleapyear - 2
totalsmall = pyear - byear - 1 - totalleap

smallyeardays = 31*7 + 30*4 + 28
leapyeardays = 31*7 + 30*4 +29

totalleapdays = totalleap*leapyeardays
totalsmalldays = totalsmall*smallyeardays

TOTALMIDDAYS = totalleapdays+totalsmalldays

bleftmonths = 12 - bmonth
ppastmonths = pmonth - 1

if (bleftmonths==0):
    pass
elif(bleftmonths==1):
    TOTALMIDDAYS = TOTALMIDDAYS + 1*31
elif(bleftmonths==2):
    TOTALMIDDAYS = TOTALMIDDAYS + 31 + 30
elif(bleftmonths==3):
    TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 30 + 31
elif(bleftmonths==4):
    TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 30 + 31 +30
elif(bleftmonths==5):
    TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 30 + 31 +30 + 31
elif(bleftmonths==6):
    TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 30 + 31 +30 + 31 + 31
elif(bleftmonths==7):
    TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 30 + 31 +30 + 31 + 31 + 30
elif(bleftmonths==8):
    TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 30 + 31 +30 + 31 + 31 + 30 + 31
elif(bleftmonths==9):
    TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 30 + 31 +30 + 31 + 31 + 30 + 31 + 30
elif(bleftmonths==10):
    TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 30 + 31 +30 + 31 + 31 + 30 + 31 + 30 + 31
elif(bleftmonths==11):
    if (byear%4==0):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 +  30 + 31 +30 + 31 + 31 + 30 + 31 + 30 +31 + 29
    elif(byear%4!=0):
        TOTALMIDDAYS = TOTALMIDDAYS + 31 + 30 + 31 +30 + 31 + 31 + 30 + 31 + 30 + 31 + 28
elif(bleftmonths==12):
    if (byear%4==0):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 +  + 30 + 31 +30 + 31 + 31 + 30 + 31 + 30 +31 + 29 + 31
    elif(byear%4!=0):
        TOTALMIDDAYS = TOTALMIDDAYS + 31 + 30 + 31 +30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31


if(pmonth%4==0):
    if (ppastmonths==0):
        pass
    elif(ppastmonths==1):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31
    elif(ppastmonths==2):
        TOTALMIDDAYS = TOTALMIDDAYS + 31 + 29
    elif(ppastmonths==3):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 29 + 31
    elif(ppastmonths==4):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 29 + 31 +30
    elif(ppastmonths==5):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 29 + 31 +30 + 31
    elif(ppastmonths==6):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 29 + 31 +30 + 31 + 30
    elif(ppastmonths==7):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 29 + 31 +30 + 31 + 30 + 31
    elif(ppastmonths==8):
       
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 29 + 31 +30 + 31 + 30 + 31 + 31
    elif(ppastmonths==9):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 29 + 31 +30 + 31 + 30 + 31 + 31 + 30
    elif(ppastmonths==10):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 29 + 31 +30 + 31 + 30 + 31 + 31 + 30 + 31
    elif(ppastmonths==11):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 29 + 31 + 30 + 31 +30+ 31 +  31 + 30 + 31 + 30

if(pmonth%4!=0):
    if (ppastmonths==0):
        pass
    elif(ppastmonths==1):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31
    elif(ppastmonths==2):
        TOTALMIDDAYS = TOTALMIDDAYS + 31 + 28
    elif(ppastmonths==3):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 28 + 31
    elif(ppastmonths==4):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 28 + 31 +30
    elif(ppastmonths==5):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 28 + 31 +30 + 31
    elif(ppastmonths==6):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 28 + 31 +30 + 31 + 30
    elif(ppastmonths==7):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 28 + 31 +30 + 31 + 30 + 31
    elif(ppastmonths==8):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 28 + 31 +30 + 31 + 30 + 31 + 31
    elif(ppastmonths==9):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 28 + 31 +30 + 31 + 30 + 31 + 31 + 30
    elif(ppastmonths==10):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 28 + 31 +30 + 31 + 30 + 31 + 31 + 30 + 31
    elif(ppastmonths==11):
        TOTALMIDDAYS = TOTALMIDDAYS + 1*31 + 28 + 31 + 30 + 31 +30+ 31 +  31 + 30 + 31 + 30


if(bmonth==1):
    TOTALMIDDAYS = TOTALMIDDAYS + 31 - bdate
elif(bmonth==2):
    if byear%4==0:
        TOTALMIDDAYS = TOTALMIDDAYS + 29 - bdate
    elif byear%4!=0:
        TOTALMIDDAYS = TOTALMIDDAYS + 28 - bdate
elif(bmonth==3):
    TOTALMIDDAYS = TOTALMIDDAYS + 31 - bdate
elif(bmonth==4):
    TOTALMIDDAYS = TOTALMIDDAYS + 30 - bdate
elif(bmonth==5):
    TOTALMIDDAYS = TOTALMIDDAYS + 31 - bdate
elif(bmonth==6):
    TOTALMIDDAYS = TOTALMIDDAYS + 30 - bdate
elif(bmonth==7):
    TOTALMIDDAYS = TOTALMIDDAYS + 31 - bdate
elif(bmonth==8):
    TOTALMIDDAYS = TOTALMIDDAYS + 31 - bdate
elif(bmonth==9):
    TOTALMIDDAYS = TOTALMIDDAYS + 30 - bdate
elif(bmonth==10):
    TOTALMIDDAYS = TOTALMIDDAYS + 31 - bdate
elif(bmonth==11):
    TOTALMIDDAYS = TOTALMIDDAYS + 30 - bdate
elif(bmonth==12):
    TOTALMIDDAYS = TOTALMIDDAYS + 31 - bdate


TOTALMIDDAYS = TOTALMIDDAYS + pdate - 1

# print(TOTALMIDDAYS)

totalhour = TOTALMIDDAYS*24 + 24 - bhour - 1 + phour
# print(totalhour)

totalmin = totalhour*60 +  60 - bmin -1 + pmin

totsec = totalmin*60 + 60 - bsec - 1 + psec

print("\nAge in seconds is the most precise among all given.")
print("\n\nAge in seconds:")
print("Your age in seconds is",totsec, "seconds.")

print("\nAge in minutes:")
print("Your age in minutes is",totalmin, "minutes.")

print("\nAge in hours:")
print("Your age in hours is",totalhour, "hrs.")

print("\nAge in days:")
print("Your age in days is",TOTALMIDDAYS, "days.")

Comments

Popular posts from this blog

Password Generator in PYTHON

Password Generator in Python:- import string import random import time s1 = string.ascii_lowercase s2 = string.ascii_uppercase s3 = string.digits s4 = string.punctuation password_length = input("Enter the length of password you want = ") password_length = int(password_length) password_list = [] a = input("Do you want lowercase letters in your password? (y/n): ") if a is "y": password_list.extend(s1) else: pass b = input("Do you want uppercase letters in your password? (y/n): ") if b is "y": password_list.extend(s2) else: pass c = input("Do you want numbers in your password? (y/n):") if c is "y": password_list.extend(s3) else: pass d = input("Do you want punctuations in your password? (y/n): ") if d is "y": password_list.extend(s4) else: pass random.shuffle(password_list) print("Generating the strongest password...") time.sleep(3) print("\n...

Binary to Decimal and Decimal to Binary Convertor in PYTHON

Binary to Decimal Convertor  Decimal to Binary Convertor in PYTHON import math while True: decision = input("\n \nPress 1 for decimal to binary conversion\nPress 2 for binary to decimal conversion\n") if(decision=="1"): print("Instructions") print("1.) Only positive numbers") print("2.) Number should not be in fraction") print("3.) It should not contains alphabets or other special characters") n = input("Enter the number: ") n = int(n) mylist = [] if n John Veer Basic Python Projects Contact mail id - john.veer.utube@gmail.com Thanks for reading www.basicpythonprogramme.blogspot.com www.basicpythonprojects.blosgpot.com