Number of leap years within a range of years

In this program, we will take a range of leap years as input and find the number of leap years within a range of years.

Steps to solve the program
  1. Take a range of years as input.
  2. Split the range using split() so that will get a list of starting year and ending year.
  3. Create a variable and assign its value equal to 0.
  4. Use for loop to get a range of years between starting year and the ending year.
  5. During iteration check whether a year is a leap year to not.
  6. If it is a leap year then add 1 to the variable that we created at the start.
  7. Print the output.
				
					#Input string
str1 ="1981-2001"
l = str1.split("-")
total = 0

for i in range(int(l[0]),int(l[1])+1):
    if (i % 400 == 0 or i % 100 !=0) and i % 4 == 0:
        total += 1
        
#Printing output
print("Range of years:", str1)
print("Total leap year: ",total)
				
			

Output :

				
					Range of years: 1981-2001
Total leap year:  5
				
			

extract name from a given email address

insert space before every capital letter appears in a given word

Leave a Comment