A day on the calendar (usual Gregorian calendar used in the USA) can be represen
ID: 3745283 • Letter: A
Question
A day on the calendar (usual Gregorian calendar used in the USA) can be represented as a tuple with three Int values (month,day,year) where the year is a positive integer, 1 <= month <= 12, and 1 <= day <= days_in_month. Here days_in_month is the number of days in the the given month (i.e. 28, 29, 30, or 31) for the given year. Develop a Boolean Haskell function validDay d that takes a date tuple d and returns True if and only if d represents a valid date. For example, validDay (8,20,2018) and validDay(2,29,2016} yield True and validDay (2,29,2017) and validDay(0,0,0) yield False.
Explanation / Answer
def isLeap(year): if year % 4 == 0: if year % 100 == 0: return year % 400 == 0 return True return False def days_in_month(month, year): days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] if month == 2: if isLeap(year): return 29 else: return 28 else: return days[month - 1] def validDay(month, day, year): if 1Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.