Basics - Simple Loops - Part 2 MOOC - Beginner Advice

Hello!

- Learning basics. I'm trying to avoid looking up the solutions, but the basics are always what deter me the most. Just looking for general advice on how to go through this.

- I slightly modified the request to just print out the next 2 leap years, but it isn't working...I'm not sure what to do or where to go with this. Spent a few hours & feeling a bit demotivated on just basics haha. (https://programming-25.mooc.fi/part-2/4-simple-loops)

  • Please write a program which asks the user for a year, and prints out the next leap year.
  • If the user inputs a year which is a leap year (such as 2024), the program should print out the following leap year:

I implemented the counter to determine if the first input was a leap year & if it was, then to print out a separate statement, but that's on the back burner because I can't seem to get the 2nd leap year to be found.

  • It just feels weird to call the input_year_2 to itself and then count 1. I'm just not following this logically & I'm not sure how to get past that bump.

Going to be rebuilding it from scratch in the mean time but thought I'd share my first failure for a review. Everything up until this point has been relatively simple, but I'm a bit lost here...

# https://programming-25.mooc.fi/part-2/4-simple-loops
## enter a year, determine if it's a leap year, if not: next leap year

input_year_1 = int(input("Year: "))
input_year_2 = input_year_1
leap_year_check1 = False
leap_year_check2 = False
leap_year_found1 = 0
leap_year_found2 = 0

leap_year_counter = 0

while leap_year_check1 == False:         #Find the first leap year

    if (input_year_1 % 4 == 0) and (input_year_1 % 100 != 0): 
        leap_year_found1 = input_year_1
        leap_year_check1 = True
    elif (input_year_1 % 100 == 0) and (input_year_1 % 400 != 0):   
        input_year_1 += 1
    elif (input_year_1 % 400 == 0):                                 
        leap_year_found1 = input_year_1
        leap_year_check1 = True
    else:
        input_year_1 += 1

while leap_year_check1 == True and leap_year_check2 == False:  

    input_year_2 = input_year_1 + 1
     
    if (input_year_2 % 4 == 0) and (input_year_2 % 100 != 0): 
        leap_year_found2 = input_year_2
        leap_year_check2 = True
    elif (input_year_2 % 100 == 0) and (input_year_2 % 400 != 0):   
        input_year_2 += 1
    elif (input_year_2 % 400 == 0):                             
        leap_year_found2 = input_year_2
        leap_year_check2 = True
    else:
        input_year_2 += 1

if leap_year_check1 == True and leap_year_check2 == True:
    print(f"Leap year 1 is: {leap_year_found1} and leap year 2 is: {leap_year_found2}")

Posted Dec 1, 2025, 3:04 AM UTC

69
Loading comments…