Your friend wants to \"take the leap\" and get married, but only during a \"leap
ID: 3869750 • Letter: Y
Question
Your friend wants to "take the leap" and get married, but only during a "leap year". A leap year is one which is divisible by four, with the exception of any that is divisible by 100, unless it is also divisible by 400. He's written a function to solve this problem, but is having trouble making it run. Help him fix his coding errors. Correct the errors within the body of the function named next_leap_year. The function should find and return the first leap year greater than or equal to the starting year received. The logic in the code is correct, but there are several syntax errors that you must find and correct. def next_leap_year (from_year): > > > next_leap_year (1900) 1904 > > > next_leap_year (1998) 2000 > > > next_leap_year (2119) 2120 year = from_year while true: if Year % 4 =! 0: else if year % 100 != 0 return year else if year % 400 != 0: year += 1 else: return yearExplanation / Answer
Correct the else if syntax
def next_leap_year(from_year):
"""
>>>next_leap_year(1900)
1904
>>>next_leap_year(1998)
2000
>>>next_leap_year(2119)
2120
"""
year=from_year
while true:
if year%4!=0:
year+=1
elif year%100!=0:
return year
elif year%400!=0:
year+=10
else:
return year
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.