我試圖找出什麼時候有人會變成10億秒。用戶在他們出生時輸入。這些值然後轉換爲秒,然後我添加10億秒並轉換回日期。但是,當我輸入特定日期時,python似乎陷入困境。這樣的例子是1993/11/05 00:00:00,python表示用戶將在第0個月交出。 注意我不能使用if/else或datetime。關於簡單的蟒蛇日期計算
繼承人我的代碼:
YEARSEC=(12*30*24*3600)
MONTHSEC=(3600*24*30)
DAYSEC=(24*3600)
HOURSEC=3600
MINUTESEC=60
year=int(input("Please enter the year in which you were born: "))
month=int(input("Please enter the month you were born: "))
day=int(input("Please enter the day you were born: "))
hour=int(input("Please enter the hour you were born: "))
minute=int(input("Please enter the minute you were born: "))
second=int(input("Please enter the second you were born: "))
year_calc=(year*YEARSEC)
month_calc=(month*MONTHSEC)
day_calc=(day*DAYSEC)
hour_calc=(hour*HOURSEC)
minute_calc=(minute*MINUTESEC)
s=(1000000000+year_calc+month_calc+day_calc+hour_calc+minute_calc+second)
year_num=int((s/YEARSEC))
s=(s-(year_num*YEARSEC))
month_num=int((s/MONTHSEC))
s=(s-(month_num*MONTHSEC))
day_num=int((s/DAYSEC))
s=(s-(DAYSEC*day_num))
hour_num=int((s/HOURSEC))
s=(s-(HOURSEC*hour_num))
minute_num=int((s/MINUTESEC))
s=(s-(MINUTESEC*minute_num))
print("You will turn 1 000 000 000 seconds old on: %04d/%02d/%02d %02d:%02d:%02d" %(year_num,month_num,day_num,hour_num,minute_num,s))
這樣做不正確的'datetime'將是一個醜陋的混亂......你爲什麼說你不能使用它? –
這可能是他的家庭作業;) – Dan