November 16 from 15:00 to 16:00

Enter a 4-digit year to display whether it is a leap year
Create a gram. (Already done) Repeat input/judgment display until end is entered. A function is used to determine the leap year. How should the function part and end part be written?
I am a beginner and spend time, but I can't solve it.

year = input ("Please enter the year!")
year = int (year)
if year% 400 == 0:
print ("閏年")
elif year% 100 == 0:
print ("average")
elif year% 4 == 0:
print ("閏年")
print ("average")
  • Answer # 1

    year = ""
    def judge (year):
        if year% 400 == 0: print ("leap year")
        elif year% 100 == 0: print ("normal year")
        elif year% 4 == 0: print ("leap year")
        else: print ("normal")
    while year! = "end":
        year = input ("Please enter the year!")
        if year! = "end":
            judge (int (year))

    Is this the case? I don't think it's very good code.

Related articles