Could someone please explain what questions I should be asking when approaching an exercise? (simple loops Q)

Posted by Slight_Total4874@reddit | learnprogramming | View on Reddit | 15 comments

I know this is quite a lengthy post, so I apologize, but would really appreciate if someone could help me.

Exercise asks -

"Please write a program which asks the user for a year, and prints out the next leap year."

Sample output:

Year: 
2023
The next leap year after 2023 is 2024

If the user inputs a year which is a leap year (such as 2024), the program should print out the following leap year:
Year: 2024
The next leap year after 2024 is 2028

The model solution:

start_year = int(input("Year: "))
year = start_year + 1


while True:
    if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
        print(f"The next leap year after {start_year} is {year}")
        break
    year += 1

What I'm having difficulty with:

I sort of managed with everything leading up to this particular question, even if I didn't fully understand/got my code wrong, after seeing the model solution, it made sense.

Tia!