fixed a typo

This commit is contained in:
Bigsk 2024-09-29 17:34:10 +08:00
parent 86ed4932b8
commit f4e8900870

View File

@ -1,14 +1,14 @@
import time import time
def calc(brith, life_expectancy): def calc(birth, life_expectancy):
# Year Month Day, Hour Minute Second # Year Month Day, Hour Minute Second
ts_brith = time.mktime(time.strptime("{}-{}-{} {}:{}:{}".format(*brith), "%Y-%m-%d %H:%M:%S")) ts_birth = time.mktime(time.strptime("{}-{}-{} {}:{}:{}".format(*birth), "%Y-%m-%d %H:%M:%S"))
# MilliSecond # MilliSecond
ts_brith += brith[-1] / 1000 ts_birth += birth[-1] / 1000
# Distance # Distance
ts_dis = time.time() - ts_brith ts_dis = time.time() - ts_birth
# Leap Year Cut Down # Leap Year Cut Down
for i in range(brith[0], int(time.strftime("%Y", time.localtime()))): for i in range(birth[0], int(time.strftime("%Y", time.localtime()))):
if not i % 4: if not i % 4:
ts_dis -= 24 * 60 * 60 ts_dis -= 24 * 60 * 60
age = ts_dis / (365 * 24 * 60 * 60) age = ts_dis / (365 * 24 * 60 * 60)
@ -16,7 +16,7 @@ def calc(brith, life_expectancy):
# Remaining Calc # Remaining Calc
time_remaining = (life_expectancy - age) * 60 * 60 * 24 * 365 time_remaining = (life_expectancy - age) * 60 * 60 * 24 * 365
# Leap Year Cut Down # Leap Year Cut Down
for i in range(BRITH[0] + int(age), BRITH[0] + int(life_expectancy)): for i in range(BIRTH[0] + int(age), BIRTH[0] + int(life_expectancy)):
if not i % 4: if not i % 4:
time_remaining += 60 * 60 * 24 time_remaining += 60 * 60 * 24
# More Remaining Calc # More Remaining Calc
@ -28,11 +28,11 @@ def calc(brith, life_expectancy):
if __name__ == "__main__": if __name__ == "__main__":
BRITH = (2005, 3, 16, 9, 0, 0, 0) # 生日,年 月 日 时 分 秒 毫秒 BIRTH = (2005, 3, 16, 9, 0, 0, 0) # 生日,年 月 日 时 分 秒 毫秒
LIFE_EXPECTANCY = 24 # 预期寿命,岁 LIFE_EXPECTANCY = 24 # 预期寿命,岁
while True: while True:
data = calc(BRITH, LIFE_EXPECTANCY) data = calc(BIRTH, LIFE_EXPECTANCY)
print("您已:{}\r".format(data[0]), end="") print("您已:{}\r".format(data[0]), end="")
time.sleep(1) time.sleep(1)
print("生命剩下 {}月/{}周/{}\r".format(data[-1], data[-2], data[-3]), end="") print("生命剩下 {}月/{}周/{}\r".format(data[-1], data[-2], data[-3]), end="")