lundi 21 septembre 2020

how to print out the next year in a while loop or if statement

I am currently doing a online practise course by myself. This is the code that i have so far. the code only prints out correctly one of the conditions. The if leap condition prints out both print statements. How do i get the if leap to only print out one statement and to ignore what comes after it.

inp_year = int(input("Give year:"))

year = inp_year

leap = year % 4 == 0 and year %100 != 0 or year % 100 == 0 and year % 400 ==0

if leap:

print("The next leap year from",year,"is",year + 4)

while not leap:

year += 1

leap = year % 4 == 0 and year %100 != 0 or year % 100 == 0 and year % 400 ==0

print("The next leap year from",inp_year,"is",year)

Aucun commentaire:

Enregistrer un commentaire