diff --git a/birthday.py b/birthday.py index a54c5ec..90bca66 100644 --- a/birthday.py +++ b/birthday.py @@ -1,5 +1,6 @@ from datetime import datetime +# A dictionary of number endings number_endings = { 1: 'st', 2: 'nd', @@ -18,17 +19,31 @@ ending = 'th' if todays_day < 10 or todays_day > 20: - # x % y (mod) will give the remainder when x is divided by y + # x % y (modulus) will give the remainder when x is divided by y # -- but x needs to be an integer! number = todays_day % 10 # look up number in number_endings # and if you find it as a key, put the value in ending if number in number_endings: + # make this print ending, not 'th' + ending = number_endings[number] + print("Today is the {0}{1}".format(todays_day, ending)) + else: + print ("Today is the {0}{1}".format(todays_day, ending)) -# make this print ending, not 'th' -print "Today is the {}th".format(todays_day) +else: + print ("Today is the {}th".format(todays_day)) -birthday = int(raw_input("What day of the month is your birthday?")) + +birthday = int(raw_input("What day of the month is your birthday? ")) # make this print the birthday, and the right ending -print "Your birthday is on the {}th!".format(todays_day) \ No newline at end of file +if birthday < 10 or birthday > 20: + number = birthday % 10 + if number in number_endings: + ending = number_endings[number] + print("Your birthday is on the {0}{1}".format(birthday, ending)) + else: + print("Your birthday is on the {0}{1}".format(birthday, ending)) +else: + print("Your birthday is on the {}th!".format(birthday)) \ No newline at end of file diff --git a/github.py b/github.py index 3d20fc7..6958f4a 100644 --- a/github.py +++ b/github.py @@ -11,7 +11,6 @@ def github_api_response(): def print_user_repository_names(): - # I just want to print out the names and descriptions of the repositories.. # like 'Hackbright-Curriculum: Exercises for the Hackbright Academy Fellowship Program' @@ -20,8 +19,9 @@ def print_user_repository_names(): for repo in repos: # I don't think I have these keys right # Also I'd like to print it on one line. - print repo['repo_name'] - print repo['repo_description'] + if repo['description']: + print repo['name']+ ": " , + print repo['description'] if __name__=="__main__": diff --git a/halloween.py b/halloween.py index e966d9d..9ee3290 100644 --- a/halloween.py +++ b/halloween.py @@ -1,6 +1,6 @@ # I can't be bothered to think of a Hallowe'en costume so # can you help me generate one randomly? - +from random import randint nouns = [] adjectives = [] @@ -15,28 +15,22 @@ for line in f: adjectives.append(line.strip()) - def generate_costume(): - # pick something random from the nouns and adjectives list - - noun = "lazy" - adj = "person" - - return (noun, adj) + noun = nouns[randint(1, len(nouns)-1)] + adj = adjectives[randint(1, len(adjectives)-1)] + return (adj, noun) while True: - (noun, adjective) = generate_costume() - - print "You go dressed as a {} {} to the party." - + (adjective, noun) = generate_costume() + print("You go dressed as a {0} {1} to the party.".format(adjective, noun)) happy = raw_input("Are you happy with this choice? ") # Check if the user typed something like 'yes' or 'y' and # quit the program if they are happy. - if happy == True: + if happy == 'y' or happy == 'yes': exit() else: - print "OK, I will choose another costume. Hold on..." + print("OK, I will choose another costume. Hold on...") print \ No newline at end of file diff --git a/icecream.py b/icecream.py index 18094be..8a4ef25 100644 --- a/icecream.py +++ b/icecream.py @@ -5,7 +5,6 @@ my_faves = ['mint', 'caramel'] -for item in my_list: - if my_faves: - print "I like {}".format(item) +for fave in my_faves: + print "I like %s" % fave diff --git a/keyboard.py b/keyboard.py index 9e86a33..d73b96b 100644 --- a/keyboard.py +++ b/keyboard.py @@ -8,19 +8,21 @@ 'violin', 'oboe', 'triangle'] def get_cat_and_instrument(position): -cat = cats[position] -instrument = instruments[position] -return "{} plays the {}".format(cat, instrument) + cat = cats[position] + instrument = instruments[position] + return "{} plays the {}".format(cat, instrument) # Print out my cat orchestra one by one total_cats = len(cats) position = 0 while True: -if position >= total_cats: - break + if position < total_cats: + print(get_cat_and_instrument(position)) + position += 1 + else: + break -print get_cat_and_instrument(position) -position += 1 - -# Could you do the assignment of cats and instruments any other ways? \ No newline at end of file +# Could you do the assignment of cats and instruments any other ways? +for index, cat in enumerate(cats): + print(get_cat_and_instrument(index)) \ No newline at end of file diff --git a/vacation.py b/vacation.py index fd00b02..9b2b124 100644 --- a/vacation.py +++ b/vacation.py @@ -32,38 +32,50 @@ def best_vacation_spot(weather_type): # wind = Hawaii # rain = New York # sun = Mexico - - return "Stay at home" + if weather_type == "snow": + spot = vacation_spots.index('Tahoe') + return vacation_spots[spot] + elif weather_type == "wind": + spot = vacation_spots.index('Hawaii') + return vacation_spots[spot] + elif weather_type == "rain": + spot = vacation_spots.index('New York') + return vacation_spots[spot] + elif weather_type == "sun": + spot = vacation_spots.index('Mexico') + return vacation_spots[spot] + else: + return "Stay at home" def vacation_activity(weather_type): # Look up the vacation activity from activities # and return just the activity itself - print activity + activity = activities[weather_type] + return activity def get_my_vacation(): - season = raw_input("What season do you want to travel? ") # check if season is in the seasons list - if not seasons: - print "Sorry, that isn't a season. I can't help you." - - # look up the weather type for that season - weather = weather_patterns[season] - - # get the best vacation spot for that type - best_vacation_spot(weather_type) + if season not in seasons: + print("Sorry, that isn't a season. I can't help you.") + else: + # look up the weather type for that season + weather = weather_patterns[season] - # get the best vacation activity for that type - vacation_activity(weather_type) + # get the best vacation spot for that type + spot = best_vacation_spot(weather) - print "You should travel to {}, where you can spend your time {}!".format(vacation_spot, vacation_activity) + # get the best vacation activity for that type + activity = vacation_activity(weather) + print("You should travel to {}, where you can spend your time {}!".format(spot, activity)) def main(): - print "Welcome to the Vacation-o-Matic!" + print("Welcome to the Vacation-o-Matic!") + return(get_my_vacation()) if __name__=="__main__":