Question

(python) Leap Year Detector Design a program that asks the user to enter a year, and...

(python) Leap Year Detector
Design a program that asks the user to enter a year, and then displays a message indicating whether that year is a leap year or not. Use the following logic to develop your algorithm:
If the year is evenly divisible by 100 and is also evenly divisible by 400, then it is a leap year. For example, 2000 is a leap year but 2010 is not.
If the year is not evenly divisible by 100, but it is evenly divisible by 4, it is a leap year. For example, 2008 is a leap year but 2009 is not.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
year = int(input("Enter an year: "))

if year % 4 == 0:
    if year % 100 == 0:
        is_leap_year = False
        if year % 400 == 0:
            is_leap_year = True
    else:
        is_leap_year = True
else:
    is_leap_year = False

if is_leap_year:
    print("The year", year, "is a leap year")
else:
    print("The year", year, "is not a leap year")

Add a comment
Know the answer?
Add Answer to:
(python) Leap Year Detector Design a program that asks the user to enter a year, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Has to be written in C++ Write a program that asks the user to enter the...

    Has to be written in C++ Write a program that asks the user to enter the month (1-12) and the year (0-2019). Validate the input and print an error and stop the program if an invalid month or year was entered. The program should then display the number of days in that month. Use the following criteria to identify leap years: Determine whether the year is divisible by 100. If it is, then it is a leap year if and...

  • Design algorithms and solve problems incorporating the three control structures. For each program in this homework,...

    Design algorithms and solve problems incorporating the three control structures. For each program in this homework, develop flowcharts, then implement the design in Java. You do not need to include function calls in your flowchart diagrams. Leap Year Detector Design and implement a Java program that asks the user to enter a year, and then displays a message indicating whether that year is a leap year or not. Algorithm: if the year is evenly divisible by 4, it is a...

  • Write a program that accepts a year and determines whether the year is a leap year....

    Write a program that accepts a year and determines whether the year is a leap year. Use the mod function. The output should be the variable extra_day, which should be 1 if the year is a leap year and 0 otherwise. The rules for determining leap years in the Gregorian calendar are as follows: All years evenly divisible by 400 are leap years. Years evenly divisible by 100 but not by 400 are not leap years. Years divisible by 4...

  • Design a solution that asks user to input two numbers. The program shall display the message...

    Design a solution that asks user to input two numbers. The program shall display the message indicating the numbers are the same or different. Present your answer in algorithm and flowchart. (note: with Decision Logic)

  • Write a class named MonthDays. The class’s constructor should accept two arguments: l An integer for...

    Write a class named MonthDays. The class’s constructor should accept two arguments: l An integer for the month (1 = January, 2 February, etc). l An integer for the year The class should have a method named getNumberOfDays that returns the number of days in the specified month. The method should use the following criteria to identify leap years: 1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and if...

  • Python Programming Task 2: Leap Years   Part A - Is this a leap year? Write a...

    Python Programming Task 2: Leap Years   Part A - Is this a leap year? Write a function is leap year(year) that calculates whether a given (CE) year is a leap year. The function must: • take one argument: a positive integer representing a year (assumed to be CE) • return True if that year was a leap year; return False if not NOTE: all years that are divisible by four are leap years, unless they are also divisible by 100,...

  • C++ code: Days in current month: Write a program that can determine the number of days...

    C++ code: Days in current month: Write a program that can determine the number of days in a month for a specified month and year. The program should allow a user to enter two integers responding a month and a year, and it should determine how many days are in the specified month. The integers 1 through 12 will be used to identify the months of January through December. The user indicates the end of days in the current month...

  • In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists...

    In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4...

  • Python help. Write a program that asks the user to enter a person's age. The program...

    Python help. Write a program that asks the user to enter a person's age. The program should display a message indicating whether the person is an infant, a child, a teenager, or an adult. Following are the guidelines: If the person is 2 year old or less, he or she is an infant. If the person is older than 2 year, but younger than 13 years, he or she is a child. If the person is at least 13 years...

  • #1 Write a MATLAB script to solve: Leap Year Program (practice your IF statements!) Write a...

    #1 Write a MATLAB script to solve: Leap Year Program (practice your IF statements!) Write a code to determine if a year is considered a leap year or not? Display to the screen if the year is a leap year or not. Use num2str() and display() or fprintf(). In the Gregorian calendar three criteria must be taken into account to identify leap years: The year is evenly divisible by 4 (Exceptions 1700, 1800, and 1900); If the year can be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT