In Python please:
The month of February normally has 28 days. But if it is a leap year, February has 29 days. Write a Python program that asks the user to enter a year. The program should then display the number of days in February that year. Use thefollowing criteria to identify leap years: • Determine whether the year is divisible by 100. If it is, then it is a leap year if and only if it is also divisible by 400. For example, 2000 is a leap year, but 2100 is not. • If the year is not divisible by 100, then it is a leap year if and only if it is divisible by 4. For example, 2004 is a leap year, but 2006 is not.

Respuesta :

Limosa

Answer:

Following are the program in the Python Programming Language.

#set variable for input year by user

y=int(input("Enter year: "))

#set variable and initialize to 0

flag=0

#check condition that year is divisible by 4

if(y%4==0):

 #check that the year is divisible by 100

 if(y%100==0):

   #check that the year is divisible by 400

   if(y%400 ==0):

     #then initialized flag to 1

     flag=1

   else:

     #otherwise remain 0

     flag = 0

 else:

   flag = 1

else:

 flag = 0

#for break line

print()

#check that if flag is equal to 1

if(flag==1):

 print("29 days in February")

#otherwise else

else:

 print("28 days in February")

Output:

Enter year: 2020

29 days in February

Explanation:

Following are the description of the program:

  • Set variable 'y' in which we get integer value as year from the user.
  • Set variable 'flag' and initialize that variable to 0.
  • Then, we set if-else conditional statements to check that the variable 'y' is divisible by 4 then, we check that the variable 'y' is divisible by 100 and we also check that the following variable is divisible by 400.
  • Finally, we set if-else conditional statement to check that the variable 'flag' is equal to 1 then print about the leap year, otherwise it print about the non-leap year.