Home > database >  Difficulty defining leap year with function, receiving error as output every time
Difficulty defining leap year with function, receiving error as output every time

Time:02-18

I am supposed to define leap year as a function. My program must define and call the following function. The function should return true if the input year is a leap year and false otherwise. This is my code, whats throwing me off mainly is the if name == 'main': , but I am required to have it for my zybooks. If anyone knows the error please let me know. My output I'm receiving is File "main.py", line 11 if is_leap ^ SyntaxError: invalid syntax

my code:

def is_leap_year(user_year)

def is_leap(year):
    leap = year % 4 == 0 and (year % 400 == 0 or year % 100 != 0)
    return leap
    

if __name__ == '__main__':
    year = int(input())
    if is_leap
        print(year,"is a leap year.")
    else
        print(year,"is not a leap year.")

CodePudding user response:

You must include the parameter in your call. Also you are missing the colon in the conditional.

def is_leap(year):
    leap = year % 4 == 0 and (year % 400 == 0 or year % 100 != 0)
    return leap
    
if __name__ == '__main__':
    year = int(input())
    if is_leap(year ): # <------ here, added year, call() and colon: 
        print(year,"is a leap year.")
    else: # <------- here, added colon
        print(year,"is not a leap year.")

CodePudding user response:

More regarding Daniel answer you need to have at least empty quotation marks in input in the 6 th line

  • Related