Answer to Question #196332 in Python for Navneet Gautam

Question #196332

1. Write a program to input a year in 4-digit form and check whether it is a leap year or not and display proper message.


1
Expert's answer
2021-05-20T18:20:18-0400
while True:
	y_str = input('year: ')
	try:
		y_int = int(y_str)
		break
	except ValueError:
		print('incorrect input')


if y_int % 100 == 0 and y_int % 400 == 0:
	print('{} is leap'.format(y_str))
elif y_int % 4 == 0 and y_int % 100 != 0:
	print('{} is leap'.format(y_str))
else:
	print('{} is not leap'.format(y_str))

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