write a python script that takes a year as input, then checks if that year is a leap year
- User
write a python script that takes a year as input, then checks if that year is a leap year
Assistant
Here's a Python script that takes a year as input and checks if it's a leap year:
def is_leap_year(year): # A year is a leap year if it's divisible by 4, # except for century years (years ending in 00) # unless they're also divisible by 400 if year % 4 != 0: return False elif year % 100 == 0: return year % 400 == 0 else: return True # Prompt the user to input a year year = int(input("Enter a year to check if it's a leap year: ")) # Call the function to check if the year is a leap year if is_leap_year(year): print(year, "is a leap year.") else: print(year, "is not a leap year.")In this script, the
is_leap_yearfunction takes a year as an argument, and returnsTrueif it's a leap year, andFalseotherwise. The function follows the leap year rule, which is:- A year is a leap year if it's divisible by 4
- Except for century years (years ending in 00), unless they're also divisible by 400
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.