################################################# # Author: # Date: # medium_functions.py ################################################# from run_tests import run_test, run_test_float, close_enough ###################FREE CODE###################################### def is_leap(year): """prec: year is a modern year postc: returns True if the year leaps. """ out = False if year %4 == 0: out = not out if year % 100 == 0: out = not out if year % 400 == 0: out = not out return out ##############END FREE CODE###################################### ###################Problem 1################ def meanie(theList): """Precondition: theList is a non-empty list of numbers Postcondition: return the mean of the numbers.""" return 0 ###################Problem 2################ # 1 is January, 2 is February, etc. def day_in_year(year, month, day): """prec: year/month/day is a valid date postc: returns the ordinal position of the day in the year (Feb 15 is the 46th day of year 2000). Hint: The built-in function sum is your friend. Learn about it.""" lengths = [31, 28 + is_leap(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] return 0 ###################Problem 3################ def days_left_in_year(year, month, day): """prec: year/month/day is a valid date postc: returns the number of days left in the year (Feb 15 is the 44th day of year 2000).""" return 0 ###################Problem 4################ def days_to_graduation(year, month, day): """prec: year/month/ is a valid date before graduation in 2020 or 2021. It's 29 May 2021. postc: returns the number of days until graduation If the year is illegal, or if a date after 29 May 2021 is entered, return "ILLEGAL INPUT" """ return 0 ###################Problem 5################ def dhms(secs): """prec: secs is a nonnegative integer postc: return a STRING of the form d:hh:mm:ss, where d is the number of days, h is the number of hours, m is the number of minutes, and s is the number of seconds, h < 24, 0 <= m, s, < 60. Give each of h, m, s a two character width, padding with zeroes as needed. """ return "" ###################Problem 6################ def water_closet(theString): """precondition: thesString is a string. postcondition: returns a tuple (c, w, l) where c is the number of characters in theString, w is the number of words, and l is the number of lines in the string""" return (0, 0, 0) ###################Problem 7################ def math_case(x): """precondition: x is a number postcondition: If x > 4, f(x) = x - 4, if x < -5, f(x) = x + 5, otherwise, f(x) = 0.""" if x > 4: return x - 4 if x < -5: return x + 5 return 0 def main(): print("###################Problem 1################") test = [[1,2,3,4,5,6]] expected = 3.5 run_test_float(meanie, expected, test) test = [[-3, -2, 0, 0, 6, 5]] expected = 1.0 run_test_float(meanie, expected, test) print("###################Problem 2################") print("###################Problem 3################") print("###################Problem 4################") print("###################Problem 5################") print("###################Problem 6################") print("###################Problem 7################") main()