I am using Python and need help creating a code I need a sim
I am using Python and need help creating a code. I need a simple and easy to understand code for Introduction to Programming using Python. Here is the exercise for the program I need:
\"6.16 (number of days in a year) Write a function that returns the number of days in a year using the following header:
def numberOfDaysInAYear(year):
Write a test program that displays the number of days in the years from 2010 to 2020.\"
I am to use a boolean expression to test for leap years as well in this program. Any help creating a simple code would be appreciated.
Solution
# program to find the number of days in year
# method to determine a year is leap year or not. Return true if leap year else false
 def isLeapYear(n):
 if (n % 4 == 0 and n % 100 != 0) or n % 400 == 0:
 return True
 else:
 return False
# method to determin the number of days for a year
 def numberOfDaysInAYear(year):
 if(isLeapYear(year)):
 print year, \'has 366 days\'
 else:
 print year, \'has 365 days\'
   
 #program to test the years in between 2010-2020
 year = 2010
 while (year <= 2020):
 numberOfDaysInAYear(year)
 year=year+1
 ///////////////////////////////////////////////////
 output
 sh-4.3$ python main.py
 2010 has 365 days   
 2011 has 365 days   
 2012 has 366 days   
 2013 has 365 days   
 2014 has 365 days   
 2015 has 365 days   
 2016 has 366 days   
 2017 has 365 days   
 2018 has 365 days   
 2019 has 365 days   
 2020 has 366 days
Note: Please find the comments for specific method. Also feel free to ask question incase of doubt. God bless you

