Question

In: Computer Science

Design and Write a program that asks for a 4-digit year and determines whether that year...

Design and Write a program that asks for a 4-digit year and determines whether that year is a leap year or not.

This should work for any year from 1700 to 2022. Anything not completely obvious to a newbie must use # notes on lines to explain. Must be modularized and repeatable. Should have an invocation of the main routine at the end of the program.

Must have Flowgorithm and Python code.

Solutions

Expert Solution

Answer

Here is your answer, any doubt please comment,

here is the code for the above problem, finding the given year is leap year or not.

def leapYear(year):
    """
    A leap year is exactly divisible by 4 except for year end with 00.
    The century year is a leap year only if it is perfectly divisible by 400
    """
    if (year % 4) == 0:  #%is used to find the reminder
        if (year % 100) == 0:
            if (year % 400) == 0:
                print("{0} is a leap year".format(year)) #format the string.
            else:
                print("{0} is not a leap year".format(year))
        else:
            print("{0} is a leap year".format(year))
    else:
        print("{0} is not a leap year".format(year))

def main():
    """
    create a loop for ask user input and check wheather it lies in between 1700 and 2020, then check it is leap year or not
    """
    while 1:
        year = int(input("Enter a year(quit enter 1): ")) #ask user for input
        if year==1: #if user enter 1 ith will break and stop the program
            break
        if year>=1700 and year<=2020:
            leapYear(year)
        else:
            print("Check the year in between 1700 - 2020")
        

if __name__=="__main__":
    main() # invocation of the main routine at the end of the program.

i put comment in the above code please look into that, any doubt in the code please comment.

output

Thanks in advance


Related Solutions

Write a program that determines whether an input string is a palindrome; that is, whether it...
Write a program that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. In Pseudocode please
Write a C++ program that asks the user to enter a series of single-digit numbers with...
Write a C++ program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. It is...
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
Design, plan, test, and write a computer program in Java that asks the user to enter...
Design, plan, test, and write a computer program in Java that asks the user to enter 1 number and a String. You will display the first n characters of the string where n is the number entered. For example, if the user enters 3 and java then you will print jav. If they enter 5 and Halloween then you print Hallo. If the user enters a number less than 0 then set the number to 0. Assume the user will...
Write a Python program called arecongruent.py that determines whether two integers a and b are congruent...
Write a Python program called arecongruent.py that determines whether two integers a and b are congruent modulo n. Your code must work as follows: From the command prompt the user runs the program by typing python arecongruent.py and then your program interface prompts the user for the values of a, b, and n. The program outputs either True or False, and the values of a mod n and b mod n. Submit your Python source code arecongruent.py. NOTE: please include...
Design a program that asks the user for a number and the program computes the factorial...
Design a program that asks the user for a number and the program computes the factorial of that number and displays the result . Implement with two different modules - one that uses a for loop and one that uses a while loop Grading Rubrick Program Compiles Cleanly  syntax errors25 pts-5 per errorProgram runs without runtime errors ( validation)run-time errors 25 pts-5 per errorProgram give correct answersLogic errors30 pts-5 per errorProgram is repeatableNot repeatable5 pts-5 ptsProgram is well modularizedBarely Modularized10 pts-...
4. Write a program that reads all numbers from a file and determines the highest and...
4. Write a program that reads all numbers from a file and determines the highest and lowest numbers. You must NOT use arrays to solve this problem! Write functions where appropriate. Programming language should be C
I am trying to write a java program that determines if an inputted year is a...
I am trying to write a java program that determines if an inputted year is a leap year or not, but I am not able to use if else statements how would I do it. I don't need the code just advice.
Q3. Write a program that simulates the 4-digit lock of the suitcase. You need to represent...
Q3. Write a program that simulates the 4-digit lock of the suitcase. You need to represent each rotatable cyllinder with some variable, it's value is going to reflect what state your lock is in. Digits are going to be 0 through 9. If 9 rotates further, it gets back to 0. If 0 rotates back, it becomes 9, just like in real suitcase locks. Then, pick a combination that opens your suitcase, like: 1-9-9-5 And pick a random starting combination....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT