Math, asked by math6131, 11 months ago

write a program that prints the next 20 leap years​

Answers

Answered by kshamnani7249
0

Answer:

CURRENT_YEAR = 2017

NOF_LEAP_YEARS = 20

# Functions

def is_leap_year(year):

if year % 4 > 0:

return False

elif year % 100 > 0:

return True

elif year % 400 > 0:

return False

else:

return True

def print_next_leap_years(current_year, nof_leap_years):

nof_leap_years_found = 0

while nof_leap_years_found < nof_leap_years:

if is_leap_year(current_year):

nof_leap_years_found += 1

print(current_year)

current_year += 1

def print_next_leap_years_with_recursion(current_year, nof_leap_years, nof_leap_years_found = 0):

if is_leap_year(current_year):

nof_leap_years_found += 1

print(current_year)

if nof_leap_years_found < nof_leap_years:

print_next_leap_years_with_recursion(current_year + 1, nof_leap_years, nof_leap_years_found)

# Main

print_next_leap_years(CURRENT_YEAR, NOF_LEAP_YEARS)

print_next_leap_years_with_recursion(CURRENT_YEAR, NOF_LEAP_YEARS)

Similar questions