- 9

How to generate next 15 leap years from a given year and populate them in a list?

2nd Apr 2017, 1:35 PM
Manasjyoti Das
Manasjyoti Das - avatar
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)
24th Dec 2018, 3:02 AM
Ashwin Kulkarni
Ashwin Kulkarni - avatar
+ 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)
29th Dec 2020, 12:57 PM
v.s.bhargavram mannepalli
v.s.bhargavram mannepalli - avatar
+ 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)
24th Aug 2019, 2:47 PM
I'm Jj
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/
26th Aug 2019, 5:22 PM
satyam gupta
satyam gupta - avatar
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()
15th Jan 2021, 1:16 PM
Christian Tamayao
Christian Tamayao - avatar
- 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
7th Jun 2019, 9:17 PM
â˜ŁïžÊœáŽ€áŽ„áŽ‹áŽ‡Ê€â˜Łïž
â˜ŁïžÊœáŽ€áŽ„áŽ‹áŽ‡Ê€â˜Łïž - avatar
- 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)
12th Jul 2019, 2:27 PM
Sayali Sondkar
Sayali Sondkar - avatar
- 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++; }
2nd Apr 2017, 4:56 PM
Edward