From 247b241041fd1158b48ce895a9f633480f37d541 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 23 Jan 2021 16:30:33 -0500 Subject: [PATCH] Auto gen all the range values for the 3.11 lab --- 3/3.12 Seasons/seasons/main.py | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 3/3.12 Seasons/seasons/main.py diff --git a/3/3.12 Seasons/seasons/main.py b/3/3.12 Seasons/seasons/main.py new file mode 100644 index 0000000..2ad4a8c --- /dev/null +++ b/3/3.12 Seasons/seasons/main.py @@ -0,0 +1,44 @@ +from datetime import datetime +import logging + +logging.basicConfig(level=logging.ERROR) + +season_dict = { +} + + +#input_month = input('Input a month to analyse: ') +#input_day = int(input('Input a day of that month: ')) + + +def convert_month_to_num(month_name): + try: + _date = datetime.strptime(month_name, "%B") + return int(_date.month) + except ValueError: + logging.warning('Was unable to convert from full month name, trying with shortname.') + try: + _date = datetime.strptime(month_name, "%b") + return int(_date.month) + except ValueError: + logging.error('Was unable to convert the month {0}! Tried long name and short name.'.format(month_name)) + return None + +def day_of_year(month,day): + # Cannot handle leap years!!! + result = int((275 * month) / 9.0) - 2 * int((month + 9) / 12.0) + day - 30 + return result + + +#print(convert_month_to_num(input_month)) +#print(day_of_year(convert_month_to_num(input_month), input_day)) + +print(day_of_year(convert_month_to_num('March'), 20)) +print(day_of_year(convert_month_to_num('June'), 20)) +print(day_of_year(convert_month_to_num('June'), 21)) +print(day_of_year(convert_month_to_num('Sep'), 21)) +print(day_of_year(convert_month_to_num('September'), 22)) +print(day_of_year(convert_month_to_num('December'), 20)) +print(day_of_year(convert_month_to_num('December'), 21)) +print(day_of_year(convert_month_to_num('March'), 19)) +