Answer to Question #279328 in Python for Talha

Question #279328

Write a program in Python programming language, which allows the user to input year value and based on the input value, the program should perform the following tasks:

  • Check whether the value entered by the user is a positive integer.
  • Generates an error massage in case of negative integer.
  • Check whether the value entered by the user is in a correct format (Year should contain 4 digits).
  • Calculate that the given year is a leap year or not.

Sample output for the wrong input:

Enter the year : -1995

wrong input !! year should be positive integer.

Enter the year : 19

wrong input !! worng input Enter the year in correct format i.e , 1980 or 2030

Sample output for the correct input:

Enter the year : 2020

2020 is a leap year

Enter the year : 2021

2021 is not a leap year






1
Expert's answer
2021-12-13T16:57:18-0500
year = int(input("Eneter a year: "))
if year < 0:
    print('wrong input !! year should be positive integer')
elif year < 1000 or year > 9999:
    print('wrong input !! worng input Enter the year in correct format i.e., 1980 or 2030')
elif year%4 == 0 and (year%100 != 0 or year%400 == 0):
    print(year, 'is a leap year')
else:
    print(year, 'is not a leap year')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS