From 89b8c976710eda2834f98ff956ca7a29fb39d187 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:32:23 -0500 Subject: [PATCH 1/7] Make a better tweet decoder --- 3/3.10 Tweet Decoder/tweet_decoder/main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 3/3.10 Tweet Decoder/tweet_decoder/main.py diff --git a/3/3.10 Tweet Decoder/tweet_decoder/main.py b/3/3.10 Tweet Decoder/tweet_decoder/main.py new file mode 100644 index 0000000..d1e9d5c --- /dev/null +++ b/3/3.10 Tweet Decoder/tweet_decoder/main.py @@ -0,0 +1,13 @@ +tweet = input('Enter abbreviation from tweet:\n') + +tweet_dict = { + 'LOL': 'LOL = laughing out loud', + 'BFN': 'BFN = bye for now', + 'FTW': 'FTW = for the win', + 'IRL': 'IRL = in real life' +} + +try: + print(tweet_dict[tweet.upper()]) +except KeyError: + print("Sorry, don't know that one") From 1b92f1d3f6af30761ed0df7247246e3befd5a1a4 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:51:03 -0500 Subject: [PATCH 2/7] Create 3.11 lab --- 3/3.11 Smallest Number/smallest_number/main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 3/3.11 Smallest Number/smallest_number/main.py diff --git a/3/3.11 Smallest Number/smallest_number/main.py b/3/3.11 Smallest Number/smallest_number/main.py new file mode 100644 index 0000000..578bbf9 --- /dev/null +++ b/3/3.11 Smallest Number/smallest_number/main.py @@ -0,0 +1,16 @@ + +def get_input(): + result = [] + print('Enter a number when prompted. Press enter to stop') + while True: + _input = input('Input a number: ') + if len(_input) == 0: + break + try: + _input = int(_input) + result.append(_input) + except ValueError: + print("Error, only accepts numbers") + return result + +print(min(get_input())) 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 3/7] 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)) + From f5ef14dee8f0af89d4afc3af7d21f8c731ac9a62 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 23 Jan 2021 16:56:48 -0500 Subject: [PATCH 4/7] Submit 3.11 lab --- 3/3.12 Seasons/seasons/main.py | 49 ++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/3/3.12 Seasons/seasons/main.py b/3/3.12 Seasons/seasons/main.py index 2ad4a8c..5ebb56c 100644 --- a/3/3.12 Seasons/seasons/main.py +++ b/3/3.12 Seasons/seasons/main.py @@ -1,44 +1,53 @@ from datetime import datetime import logging -logging.basicConfig(level=logging.ERROR) +logging.basicConfig(level=logging.DEBUG) -season_dict = { -} +input_month = input('Input a month to analyse: ') +input_day = int(input('Input a day of that month: ')) +def convert_doy_to_season(doy): + if not isinstance(doy, int): + return 'Invalid' -#input_month = input('Input a month to analyse: ') -#input_day = int(input('Input a day of that month: ')) - + if 79 <= doy <= 171: + return 'Spring' + if 172 <= doy <= 264: + return 'Summer' + if 265 <= doy <= 354: + return 'Autumn' + if 355 <= doy <= 365 or 1 <= doy <= 78: + return 'Winter' def convert_month_to_num(month_name): try: _date = datetime.strptime(month_name, "%B") + logging.debug(_date.month) 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") + logging.debug(_date.month) 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 + try: + # Cannot handle leap years!!! + if day > 30 or day <= 0: + raise OverflowError + + result = int((275 * month) / 9.0) - 2 * int((month + 9) / 12.0) + day - 30 + logging.debug(result) + return result + except TypeError: + return None + except OverflowError: + return None -#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)) +print(convert_doy_to_season(day_of_year(convert_month_to_num(input_month), input_day))) From cb99c6af491ecae046cfb06b9933afd0831bd631 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 23 Jan 2021 17:04:13 -0500 Subject: [PATCH 5/7] Adjust the default logging level --- 3/3.12 Seasons/seasons/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3/3.12 Seasons/seasons/main.py b/3/3.12 Seasons/seasons/main.py index 5ebb56c..3e0c082 100644 --- a/3/3.12 Seasons/seasons/main.py +++ b/3/3.12 Seasons/seasons/main.py @@ -1,7 +1,7 @@ from datetime import datetime import logging -logging.basicConfig(level=logging.DEBUG) +logging.basicConfig(level=logging.ERROR) input_month = input('Input a month to analyse: ') input_day = int(input('Input a day of that month: ')) From d27d5025fbfbbb64d803ca9785ce63eb9692ccfe Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 23 Jan 2021 18:47:51 -0500 Subject: [PATCH 6/7] Boring exact change solution --- 3/3.13 Exact Change/exact_change/main.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 3/3.13 Exact Change/exact_change/main.py diff --git a/3/3.13 Exact Change/exact_change/main.py b/3/3.13 Exact Change/exact_change/main.py new file mode 100644 index 0000000..5314803 --- /dev/null +++ b/3/3.13 Exact Change/exact_change/main.py @@ -0,0 +1,24 @@ +try: + user_cents = int(input('Cents: ')) +except ValueError: + print('Cannot cannot parse input.') + exit() + +change = [] + +while user_cents > 100: + user_cents -= 100 + change.append('Dollar') +while user_cents > 25: + user_cents -= 25 + change.append('Quarter') +while user_cents > 10: + user_cents -= 10 + change.append("Dime") +while user_cents > 5: + user_cents -= 5 + change.append("Nickel") +for _i in range(user_cents): + change.append("Penny") + +print(change) From ab881dd5789eff801399dca511ab93a8a42cf435 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 23 Jan 2021 19:36:45 -0500 Subject: [PATCH 7/7] Final fix to exact change --- 3/3.13 Exact Change/exact_change/main.py | 36 +++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/3/3.13 Exact Change/exact_change/main.py b/3/3.13 Exact Change/exact_change/main.py index 5314803..db6aa11 100644 --- a/3/3.13 Exact Change/exact_change/main.py +++ b/3/3.13 Exact Change/exact_change/main.py @@ -5,20 +5,36 @@ except ValueError: exit() change = [] +coins = [ + ['Dollars', 'Dollar'], + ['Quarters', 'Quarter'], + ['Dimes', 'Dime'], + ['Nickels', 'Nickel'], + ['Pennies', 'Penny']] -while user_cents > 100: +while user_cents >= 100: user_cents -= 100 - change.append('Dollar') -while user_cents > 25: + change.append(coins[0]) +while user_cents >= 25: user_cents -= 25 - change.append('Quarter') -while user_cents > 10: + change.append(coins[1]) +while user_cents >= 10: user_cents -= 10 - change.append("Dime") -while user_cents > 5: + change.append(coins[2]) +while user_cents >= 5: user_cents -= 5 - change.append("Nickel") + change.append(coins[3]) for _i in range(user_cents): - change.append("Penny") + change.append(coins[4]) + +if len(change) != 0: + for coin in coins: + num_coins = change.count(coin) + if num_coins != 0: + if num_coins > 1: + print('{0} {1}'.format(num_coins, coin[0])) + else: + print('{0} {1}'.format(num_coins, coin[1])) +else: + print('No change ') -print(change)