Calculating Year, Month and Day of Life

hokiegal99 hokiegal99 at hotmail.com
Sat Jul 5 15:51:58 EDT 2003


hokiegal99 wrote:

> hokiegal99 wrote:
> 
>> Hello,
>>
>> I am a funeral director trying to write a small program that 
>> calculates the number of years, months and days a person has lived by 
>> entering the year, month and day of their birth. This is what I have 
>> so far:
>>
>> #---------------------
>> from time import *
>> local = localtime()
>>
>> print "Enter the year of birth:"; y = input()
>> print "Enter the month of birth:"; m = input()
>> print "Enter the day of birth:"; d = input()
>>
>> age = y,m,d
>> print age
>> print local
>> #----------------------
>>
>> The output looks similiar to this:
>> (1934, 2, 7)
>> (2003, 7, 5, 13, 20, 0, 5, 186, 1)
>>
>> My problem is that localtime is a list of 9 integers while age is a 
>> list of 3 integers. Is it possible to make localtime() only return the 
>> first 3 integers? If so, how would I then do calculations on the two 
>> lists' individual parts? For example, how would I instruct localtime() 
>> to subtract the first integer from age's list from the first intger in 
>> its own list (2003 - 1934)?
>>
>> Also, I am new to python, but I like it a lot and have picked it up 
>> quickly. If my approach to this solving this problem is completely 
>> wrong, please point me in the right direction.
>>
>> Thanks in advance!!!
>>
> 
> Sorry to respond to my own post, but I answered the first part of my 
> question by experimenting a bit. I pulled the first 3 integers from 
> localtime() like this:
> 
> local = localtime()
> print local[:3]
> (2003, 7, 5)
> 

Once again, I'm making progress on my own. Here's where I stand now:

----------------------
from time import *
local = localtime()

y = input("Enter the year of birth: ")
m = input("Enter the month of birth: ")
d = input("Enter the day of birth: ")
	
age = y,m,d
print "You are", local[0] - age[0], "years", local[1] - age[1], "months"
-----------------------







More information about the Python-list mailing list