Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Weather-Music-Chatbot/ageCalculater.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (38 sloc)
1.97 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import time | |
def age(day, month, year, hour, minute, second, date, daysInMonth): | |
seconds, minute = timeAdjuster(second, minute, int(date[17:19]), 60, daysInMonth) | |
minutes, hour = timeAdjuster(minute, hour, int(date[14:16]), 60, daysInMonth) | |
hours, day = timeAdjuster(hour, day, int(date[11:13]), 24, daysInMonth) | |
days, month = timeAdjuster(day, month, int(date[8:10]), daysInMonth[int(date[5:7])-1], daysInMonth) | |
months, year = timeAdjuster(month, year, int(date[5:7]), 12, daysInMonth) | |
years = int(date[0:4]) - year | |
print("\nYour are {0} years {1} months {2} days {3} hours {4} minutes and {5} seconds old".format(years, months, days, hours, minutes, seconds)) | |
def timeAdjuster(unit, nextUnit, section, num, daysInMonth): | |
units = int(section) - unit | |
if units < 0: | |
units = num + units | |
nextUnit += 1 | |
return(units, nextUnit) | |
def getAge(): | |
daysInMonth = {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31} | |
date = str(datetime.fromtimestamp(time.time())) | |
loop = True | |
while loop == True: | |
day = int(input("\nEnter the day you were born: ")) | |
month = int(input("Enter the month you were born: ")) | |
year = int(input("Enter the year you were born: ")) | |
hour = int(input("Enter the hour you were born: ")) | |
minute = int(input("Enter the minute you were born: ")) | |
second = int(input("Enter the second you were born: ")) | |
if month > 0 and month < 13: | |
if year <= int(date[0:4]) and year > -7000000: | |
if hour > 0 and hour < 25: | |
if minute >= 0 and minute < 60: | |
if second >= 0 and second < 60: | |
if day <= daysInMonth[month] and day > 0: | |
loop = False | |
elif day == 29 and month == 2 and year%4 == 0: | |
loop = False | |
else: | |
print("\nINVALID INPUT") | |