Aug-15-2018, 04:09 AM
Some observations:
'Explicit is better than implicit':
Your current way of taking input from user can be optimized. You can ask input once and parse date from that without converting input. There is
'Explicit is better than implicit':
datetime.datetime.today()
says explicitly that I am interested in (to)day. datetime.datetime.now()
says implicitly that I am interested in current point of time. You will have correct number of days in both ways but it's zen to signal your intentions explicitly.Your current way of taking input from user can be optimized. You can ask input once and parse date from that without converting input. There is
strptime
(string-parse-time) method in datetime. You can do this way:>>> answer = input('Please enter your birthday in dd/mm/yyyy format: ') Please enter your birthday in dd/mm/yyyy format: 01/01/2000 >>> birthdate = datetime.datetime.strptime(answer, '%d/%m/%Y') >>> (datetime.datetime.today() - birthdate).days 6801You will get ValueError if user input is not in correct format.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.