Write a Program in Python to Find Year in Leap Year or Not.
Answers
Answered by
2
Answer:
The given program is written in Python.
def year(n):
if len(str(n))!=4:
print("Invalid Input.")
else:
if n%4==0:
if n%100==0:
if n%400==0:
print(f"{n} is a leap year.")
else:
print(f"{n} is not a leap year.")
else:
print(f"{n} is a leap year.")
else:
print(f"{n} is not a leap year.")
# Main Códe
while True:
year(int(input("Enter Year:")))
print("Do you want to continue? (Y/N)")
x=input()[0].upper()
if x=='N':
break
Leap years are always divisible by 4. However, if the year is a century year, it must be divisible by 400 to be a leap year. Using this logic, problem is solved.
Refer to the attachment for output.
•••♪
Attachments:
Similar questions
Computer Science,
1 month ago
Social Sciences,
3 months ago
Math,
3 months ago
Social Sciences,
10 months ago
Political Science,
10 months ago