二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 2, Day 4

Record#

Today's exercise seems to be a comprehensive training, and the question is to calculate how many seconds are in a year. Because of the existence of leap years, it is not a 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 I vaguely remember it after careful recollection.

Just to be safe, I found a more accurate answer on Zhihu, but in a very long time, this answer is not perfect either.

①A leap year is one that is divisible by 4 but not by 100; ②A common year is one that is divisible by 100 but not by 400; ③A leap year is one that is divisible by 400 but not by 3200; ④A common year is one that is divisible by 3200 but not by 172800; ⑤A leap year is one that is divisible by 172800.

The answer from Zhihu and Python have fried my brain, let's make a simple judgment.

CODE#

y = int(input("Please 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("There are", m, "seconds in the year", y)


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.