Merge pull request 'week-3' (#4) from week-3 into master
Reviewed-on: https://kitsunehosting.net/gitea/Kenwood/SNHU-IT-140/pulls/4
This commit is contained in:
commit
97bc27ebd1
|
@ -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")
|
|
@ -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()))
|
|
@ -0,0 +1,53 @@
|
||||||
|
from datetime import datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.ERROR)
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
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):
|
||||||
|
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_doy_to_season(day_of_year(convert_month_to_num(input_month), input_day)))
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
try:
|
||||||
|
user_cents = int(input('Cents: '))
|
||||||
|
except ValueError:
|
||||||
|
print('Cannot cannot parse input.')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
change = []
|
||||||
|
coins = [
|
||||||
|
['Dollars', 'Dollar'],
|
||||||
|
['Quarters', 'Quarter'],
|
||||||
|
['Dimes', 'Dime'],
|
||||||
|
['Nickels', 'Nickel'],
|
||||||
|
['Pennies', 'Penny']]
|
||||||
|
|
||||||
|
while user_cents >= 100:
|
||||||
|
user_cents -= 100
|
||||||
|
change.append(coins[0])
|
||||||
|
while user_cents >= 25:
|
||||||
|
user_cents -= 25
|
||||||
|
change.append(coins[1])
|
||||||
|
while user_cents >= 10:
|
||||||
|
user_cents -= 10
|
||||||
|
change.append(coins[2])
|
||||||
|
while user_cents >= 5:
|
||||||
|
user_cents -= 5
|
||||||
|
change.append(coins[3])
|
||||||
|
for _i in range(user_cents):
|
||||||
|
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 ')
|
||||||
|
|
Loading…
Reference in New Issue