From c79d41a9520fc42f43903b8fd559099b7a8f1889 Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Mon, 4 May 2015 19:52:03 -0700 Subject: [PATCH 01/11] Fixes all bugs in birthday.py --- birthday.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/birthday.py b/birthday.py index a54c5ec..adf223e 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' + # print "Today is the {}th".format(todays_day) + ending = number_endings[number] + print "Today is the %s%s" % (todays_day, ending) + else: + print "Today is the %sth" % todays_day +else: + print "Today is the %sth" % todays_day -# make this print ending, not 'th' -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 +# print "Your birthday is on the {}th!".format(todays_day) +if birthday < 10 or birthday > 20: + number = birthday % 10 + if number in number_endings: + ending = number_endings[number] + print "Your birthday is on the %s%s" % (birthday, ending) + else: + print "Your birthday is on the %s" % birthday +else: + print "Your birthday is on the %sth!" % birthday \ No newline at end of file From a575e80b8c3c9a0e1415ff034fcc4c2e3ba94078 Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Mon, 4 May 2015 19:53:16 -0700 Subject: [PATCH 02/11] Fixes all pugs in icecream.py --- icecream.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 From e82868d50f53dc52ebff86310339c7f4925f363a Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Mon, 4 May 2015 20:15:11 -0700 Subject: [PATCH 03/11] Updates code to work with .format in python 3 --- birthday.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/birthday.py b/birthday.py index adf223e..c4ffa3d 100644 --- a/birthday.py +++ b/birthday.py @@ -28,13 +28,18 @@ # make this print ending, not 'th' # print "Today is the {}th".format(todays_day) ending = number_endings[number] - print "Today is the %s%s" % (todays_day, ending) + # print "Today is the %s%s" % (todays_day, ending) + print("Today is the {0}{1}".format(todays_day, ending)) else: - print "Today is the %sth" % todays_day + # print "Today is the %sth" % todays_day + print ("Today is the {0}{1}".format(todays_day, ending)) + else: - print "Today is the %sth" % todays_day + # print "Today is the %sth" % todays_day + print ("Today is the {}th".format(todays_day)) + -birthday = int(raw_input("What day of the month is your birthday? ")) +birthday = int(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) @@ -42,8 +47,11 @@ number = birthday % 10 if number in number_endings: ending = number_endings[number] - print "Your birthday is on the %s%s" % (birthday, ending) + # print "Your birthday is on the %s%s" % (birthday, ending) + print("Your birthday is on the {0}{1}".format(birthday, ending)) else: - print "Your birthday is on the %s" % birthday + # print "Your birthday is on the %s" % birthday + print("Your birthday is on the {}".format(birthday)) else: - print "Your birthday is on the %sth!" % birthday \ No newline at end of file + # print "Your birthday is on the %sth!" % birthday + print("Your birthday is on the {}th!".format(birthday)) \ No newline at end of file From 7abc286644fd5e084087d56c02be8cc45bb8567f Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Mon, 4 May 2015 20:38:54 -0700 Subject: [PATCH 04/11] Fixes keyboard.py and adds alternate solution --- keyboard.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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 From da771861a9bfd8451aa5ef15949f873cbf4ec66c Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Mon, 4 May 2015 20:57:59 -0700 Subject: [PATCH 05/11] Prints out names and descriptions of repos that have descriptions --- github.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github.py b/github.py index 3d20fc7..55948ec 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'], end=': ') + print(repo['description']) if __name__=="__main__": From 801545234383a8ac9857e806123214235cda162a Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Mon, 4 May 2015 21:21:33 -0700 Subject: [PATCH 06/11] Costume generator is working as described --- halloween.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/halloween.py b/halloween.py index e966d9d..53b7da1 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." - - happy = raw_input("Are you happy with this choice? ") + (adjective, noun) = generate_costume() + print("You go dressed as a {0} {1} to the party.".format(adjective, noun)) + happy = 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 From 13bd043ff2013ca465b72614ac4536e76990a00d Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Mon, 4 May 2015 21:37:01 -0700 Subject: [PATCH 07/11] Vacation recommendation engine is working as described --- vacation.py | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/vacation.py b/vacation.py index fd00b02..5e82229 100644 --- a/vacation.py +++ b/vacation.py @@ -32,38 +32,46 @@ def best_vacation_spot(weather_type): # wind = Hawaii # rain = New York # sun = Mexico - - return "Stay at home" + if weather_type == "snow": + return vacation_spots[0] + elif weather_type == "wind": + return vacation_spots[1] + elif weather_type == "rain": + return vacation_spots[2] + elif weather_type == "sun": + return vacation_spots[3] + 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? ") + season = 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__": From 4f4f9a4216f8f5a606448e5e82713466e40cda3a Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Tue, 5 May 2015 20:54:40 -0700 Subject: [PATCH 08/11] Updates files to work with Python 2.7 --- github.py | 4 ++-- vacation.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/github.py b/github.py index 55948ec..6958f4a 100644 --- a/github.py +++ b/github.py @@ -20,8 +20,8 @@ def print_user_repository_names(): # I don't think I have these keys right # Also I'd like to print it on one line. if repo['description']: - print(repo['name'], end=': ') - print(repo['description']) + print repo['name']+ ": " , + print repo['description'] if __name__=="__main__": diff --git a/vacation.py b/vacation.py index 5e82229..8dd9085 100644 --- a/vacation.py +++ b/vacation.py @@ -52,7 +52,7 @@ def vacation_activity(weather_type): def get_my_vacation(): - season = input("What season do you want to travel? ") + season = raw_input("What season do you want to travel? ") # check if season is in the seasons list if season not in seasons: From e4d353030a96d022912d92448a8186d07ce8f3f7 Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Tue, 5 May 2015 21:03:17 -0700 Subject: [PATCH 09/11] Adds searching the vacation spots list --- vacation.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vacation.py b/vacation.py index 8dd9085..9b2b124 100644 --- a/vacation.py +++ b/vacation.py @@ -33,13 +33,17 @@ def best_vacation_spot(weather_type): # rain = New York # sun = Mexico if weather_type == "snow": - return vacation_spots[0] + spot = vacation_spots.index('Tahoe') + return vacation_spots[spot] elif weather_type == "wind": - return vacation_spots[1] + spot = vacation_spots.index('Hawaii') + return vacation_spots[spot] elif weather_type == "rain": - return vacation_spots[2] + spot = vacation_spots.index('New York') + return vacation_spots[spot] elif weather_type == "sun": - return vacation_spots[3] + spot = vacation_spots.index('Mexico') + return vacation_spots[spot] else: return "Stay at home" From d064cf063f7118ea3063c95854e316f45962c26c Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Thu, 7 May 2015 19:08:34 -0700 Subject: [PATCH 10/11] Fixes a python 3 specific syntax error --- halloween.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/halloween.py b/halloween.py index 53b7da1..9ee3290 100644 --- a/halloween.py +++ b/halloween.py @@ -25,7 +25,7 @@ def generate_costume(): while True: (adjective, noun) = generate_costume() print("You go dressed as a {0} {1} to the party.".format(adjective, noun)) - happy = input("Are you happy with this choice? ") + 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. From 129ca4f5ec05ce523afe3fa9e2abe6a2903484df Mon Sep 17 00:00:00 2001 From: Bridget Carberry Date: Thu, 7 May 2015 19:22:27 -0700 Subject: [PATCH 11/11] Fixes bug when entering 30 as birthday --- birthday.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/birthday.py b/birthday.py index c4ffa3d..90bca66 100644 --- a/birthday.py +++ b/birthday.py @@ -26,32 +26,24 @@ # and if you find it as a key, put the value in ending if number in number_endings: # make this print ending, not 'th' - # print "Today is the {}th".format(todays_day) ending = number_endings[number] - # print "Today is the %s%s" % (todays_day, ending) print("Today is the {0}{1}".format(todays_day, ending)) else: - # print "Today is the %sth" % todays_day print ("Today is the {0}{1}".format(todays_day, ending)) else: - # print "Today is the %sth" % todays_day print ("Today is the {}th".format(todays_day)) -birthday = int(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) if birthday < 10 or birthday > 20: number = birthday % 10 if number in number_endings: ending = number_endings[number] - # print "Your birthday is on the %s%s" % (birthday, ending) print("Your birthday is on the {0}{1}".format(birthday, ending)) else: - # print "Your birthday is on the %s" % birthday - print("Your birthday is on the {}".format(birthday)) + print("Your birthday is on the {0}{1}".format(birthday, ending)) else: - # print "Your birthday is on the %sth!" % birthday print("Your birthday is on the {}th!".format(birthday)) \ No newline at end of file