Record#
Today's exercise seems to be a comprehensive training, the task is to calculate how many seconds are in a year. Because of the existence of leap years, it is not simply the product of multiple numbers, so it is necessary to first determine whether a certain year is a leap year. This should be a knowledge point from elementary school, and upon careful recollection, it still vaguely remembers.
To be on the safe side, I found a more accurate answer on Zhihu, but looking at it for a very long time, this answer is not perfect either.
① A year that can be divided by 4 but not by 100 is a leap year; ② A year that can be divided by 100 but not by 400 is a common year; ③ A year that can be divided by 400 but not by 3200 is a leap year; ④ A year that can be divided by 3200 but not by 172800 is a common year; ⑤ Any year that can be divided by 172800 is a leap year.
The answer on Zhihu and Python have fried my brain, let's make a simple judgment.
CODE#
y = int(input("Enter the year to calculate? "))
if y % 4 == 0 and (y % 100 != 0 or y % 400 == 0):
print(y, "is a leap year")
m = y * 366 * 24 * 60 * 60
else:
print(y, "is not a leap year")
m = y * 365 * 24 * 60 * 60
print(y, "has", m, "seconds")