+ 2

Number of days in a year

Is it possible to find number of days in a year by using Python?

3rd Apr 2020, 5:54 PM
MD. Jashim Uddin
MD. Jashim Uddin - avatar
10 Antworten
- 1
Try this..just input a year...format YYYY:- import calendar mycal = calendar.Calendar() counter = 0 year = mycal.yeardayscalendar(int(input("Enter a year format YYYY"))) for month in year: for weeks in month: for days in weeks: for day in days: if day != 0: counter += 1 print(counter)
3rd Apr 2020, 9:53 PM
rodwynnejones
rodwynnejones - avatar
+ 5
the summary of their comments is -- a = int(input('please enter the year':)) b = "there are 365 days" c = "there are 366 days" if a%4 == 0 and a%400 != 0: print(c) elif a%4 == 0 and a%400 == 0: print(b) else: print(b)
5th Apr 2020, 11:32 AM
M Tamim
M Tamim - avatar
+ 3
Yes possible in all languages. Btw in one year there is 365 days or 366 days if the year is leap year so it is not difficult to find. year = int(input()) if year % 4 == 0: print(366) else: print(365) Edited - this is just example to check leap year. To check leap year we have to also check if year is divisible by 100 or 400 because some years which are divisible by 4 are not leap year.
3rd Apr 2020, 6:06 PM
A͢J
A͢J - avatar
+ 2
AJ #Level 20 End Day your formula is not exactly correct. You also have to check if year is divisible by 100 and by 400. https://en.m.wikipedia.org/wiki/Leap_year
3rd Apr 2020, 7:01 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Not all "years" divisible by 4 are a leap years e.g 1900, 2100, 2200, 2300 are divisible but are not leap years. import calendar print([x for x in range(1900, 2220) if calendar.isleap(x)])
3rd Apr 2020, 7:09 PM
rodwynnejones
rodwynnejones - avatar
+ 2
Tibor Santa Maybe but that was just example. Btw mostly people doesn't know 100 or 400. Thanks to tell.
3rd Apr 2020, 7:18 PM
A͢J
A͢J - avatar
+ 1
import calendar print(366 if calendar.isleap(int(input())) else 365)
3rd Apr 2020, 6:33 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Yes it is possible
4th Apr 2020, 10:55 AM
Dhyey Patel
+ 1
You may find answer in http://python.6.x6.nabble.com/how-many-days-in-one-year-td4906995.html
5th Apr 2020, 3:50 PM
narayanaprasad
narayanaprasad - avatar
0
Yes sure...
5th Apr 2020, 9:51 AM
Priyanka Jadhav
Priyanka Jadhav - avatar