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

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 

Stone-Paper-Scissor in PYTHON

import random import time mylist = [ 1 , 2 , 3 ] print ( "Welcome to the Stone-Paper-Scissor game." ) print ( " \n Here are some of the rules" ) print ( "1.) There will be five round. The one whose score is more will be declared as winner." ) print ( "1.) For Stone, simply press 1." ) print ( "2.) For Paper, simply press 2." ) print ( "3.) For Scissor, simply press 3." ) print ( " \n Now, Lets go!" ) i = 0 j = 0 k = 1 for k in range ( 1 , 6 ):     print ( " \n ROUND " , k )     y = int ( input ( " \n Enter your choice as 1, 2 and 3 as instructed above: " ))     m = random . choice ( mylist )     if y == 1 :         if m == 1 :             print ( " \n Tie" )         elif m == 2 :             print ( " \n Computer chose paper, so you lose. Try again." )             j = j + 1       ...