Q. A year is a leap year if it is divisible by 100 are not leap year unless they are also divisible by 400. Write a program that asks the user for a year and print out weather it is a leap year or not.


You can understand by Watching video :-



Answer :-

year = int(input("Enter a year = "))
if year % 100 == 0 :
  if year % 400 == 0 :
    print("Leap year ")
  else :
    print("It is not leap year")
elif year % 4 == 0 :
  print("Leap year 4 ")
else :
  print("It is not leap year ")

Output :-

Enter a year = 2000
Leap year

>>> 

Enter a year = 2016
Leap year 4

>>> 

Enter a year = 2022
It is not leap year

>>>

9 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. you can use 'and' instead of nested if,
    no problems with the code

    ReplyDelete
    Replies
    1. Yes, we can use 'and' operator in place of nested if.
      I did not use 'and' operator because many students are not able to understand such type of program.

      Delete
  2. hii pathwallah moderator, how are you, hope you have a better day, i will greet you everyday except thursday and sunday. so talk what you want with me

    ReplyDelete
    Replies
    1. mr pathwallah moderator this is giri_free, want to be friends with you

      Delete
    2. Anonymous=giri_free

      Delete
    3. Thank you : )

      Please send me message on telegram or instagram.
      Telegram ( recommended )

      Delete
    4. what is your a telegram id

      Delete
  3. thank you very much for replying me, may i know what is your work as a pathwallah moderator, i wish you best for your future endeavours

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post