- 9
How to generate next 15 leap years from a given year and populate them in a list?
8 Respostas
+ 3
def find_leap_years(given_year):
count=0
list_of_leap_years=[]
while(count<15):
if(given_year%4==0 or given_year%400==0 and given_year%100==0):
list_of_leap_years.append(given_year)
count=count+1
given_year=given_year+1
return list_of_leap_years
list_of_leap_years=find_leap_years(1950)
print(list_of_leap_years)
+ 2
def find_leap(year):
count=0
leap_years=[]
while(count<15):
if(year%400==0 or (year%4==0 and year%100!=0)):
leap_years.append(year)
count=count+1
year=year+1
return leap_years
y=int(input())
leap_list=find_leap(y)
print(leap_list)
+ 1
Above solution submitted by Ashwin Kulkarni is wrong ,
for the input 96 it gives 100,104,106.... but 100 year or century year is not a leap year, there is logical error in if statement
correct solution is:
def find_leap_years(given_year):
jsn=0
list_of_leap_years=[]
while(jsn<15):
if(given_year%4==0 and given_year%100!=0) or given_year%400==0:
list_of_leap_years.append(given_year)
jsn=jsn+1
given_year=given_year+1
return list_of_leap_years
list_of_leap_years=find_leap_years(2015)
print(list_of_leap_years)
0
#PF-Assgn-22
def find_leap_years(given_year):
list_of_leap_years=[]
# Write your logic her
count=0
for i in range(1,64):
if(given_year%400==0):
list_of_leap_years.append(given_year)
count+=1
elif(given_year%100==0):
j=0
elif(given_year%4==0):
list_of_leap_years.append(given_year)
count+=1
else:
j=0
if(count==15):
break
given_year=given_year+1
return list_of_leap_years
list_of_leap_years=find_leap_years( 1996)
print(list_of_leap_years)
All infytq Question ->http://infytq.ezyro.com/category/infytq-question/page/2/
0
year = int(input("Enter Year: "))
count = 0
if year % 4 == 0 and(year % 100 != 0 or year % 400 == 0):
print(year)
else:
print(year ," is not a leap year")
input()
exit()
while count != 5:
count += 1
year = year + 4
print (year)
input()
- 1
what if list_of_leap_years=find_leap_years(2001)
i don't want any output to be shown even "[]" those are not to be shown in the output for 2001 year nothing should be returned
- 1
def find_leap_years(given_year):
count=0
list_of_leap_years=[]
while(count<15):
if(given_year%4==0 and given_year%100!=0)or(given_year%400==0):
list_of_leap_years.append(given_year)
count=count+1
given_year=given_year+1
else:
given_year=given_year+1
return list_of_leap_years
list_of_leap_years=find_leap_years(2000)
print(list_of_leap_years)
- 2
well first ask the user to input a year. then starting from that year increment by 1 in a while loop. so while (leapyearsfound < 15) {
if (isleapyear) list.add (year);
year++;
}