Home > other >  Once upon the input for a few days a year, enter a month, the output this year how many days a month
Once upon the input for a few days a year, enter a month, the output this year how many days a month

Time:10-14

Python
Once upon a few days
Input a year, a month, the output this year the month, how many days????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
A, b=eval (input ())
If b==2:
If a % 4==0 and a % 100!=0 or a % 400==0:
Print (" {} {} month has 29 days ". The format (a, 2))
The else:
Print (" {} {} month has 28 days ". The format (a, 2))
Elif b==1 or 3 or 5 or 7 or 8 or 10 or 12:
Print (" {} {} years months have 31 days ". The format (a, b))
The else:
Print (" {} {} years months have 30 days to ". The format (a, b))
One example has been not, also don't know is which instance, with bosses to see where is wrong, or have more simple without mistakes?

CodePudding user response:

This may be a more tricky problem
Example: 86400,

But it is said that 86400 is not a leap year, ha ha
Baidu yourself,

CodePudding user response:

There are simple, a ready-made library, called the calendar, but the small function as far as possible not guide library

But does not guide library means that write their own, nonono, go to the calendar chaozuoye,
As for the 86400 is not a leap year, this is because the third judge, for a lot of value, if divisible by 3200, and divisible by 172800 is a leap year
But it's no use, do you want from the second big bang...

 
Mdays=[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

February=2

Def monthlen (year, month) :
Return mdays [month] + (the month==February and isleap (year))

Def isleap (year) :
"" "Return True for leap years, False for non - leap years. "" "
Return year % 4==0 and (year % 100!=0 or 400 year %==0)
  • Related