+ 2
Number of days in a year
Is it possible to find number of days in a year by using Python?
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)
+ 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)
+ 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.
+ 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
+ 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)])
+ 2
Tibor Santa Maybe but that was just example. Btw mostly people doesn't know 100 or 400. Thanks to tell.
+ 1
import calendar
print(366 if calendar.isleap(int(input())) else 365)
+ 1
Yes it is possible
+ 1
You may find answer in http://python.6.x6.nabble.com/how-many-days-in-one-year-td4906995.html
0
Yes sure...