Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions birthday.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from datetime import datetime

number_endings = {
0: 'th',
1: 'st',
2: 'nd',
3: 'rd'
3: 'rd',
4: 'th',
5: 'th',
6: 'th',
7: 'th',
8: 'th',
9: 'th',
}

today = datetime.now()
Expand All @@ -15,20 +22,28 @@
# test your code by forcing todays_day to be something different
# todays_day = 11

ending = 'th'

if todays_day < 10 or todays_day > 20:
# x % y (mod) 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:
def date_ending(input_date):
if input_date == 11:
ending = 'th'
elif input_date == 21 or input_date == 31:
ending = 'st'
elif input_date < 10 or input_date > 20:
# x % y (mod) will give the remainder when x is divided by y
# -- but x needs to be an integer!
number = input_date % 10
# look up number in number_endings
# and if you find it as a key, put the value in ending
ending = number_endings[number]
return ending

today_ending = date_ending(todays_day)

# make this print ending, not 'th'
print "Today is the {}th".format(todays_day)
print "Today is the {}".format(todays_day) + str(today_ending)

birthday = int(raw_input("What day of the month is your birthday?"))

birthday_ending = date_ending(birthday)

# make this print the birthday, and the right ending
print "Your birthday is on the {}th!".format(todays_day)
print "Your birthday is on the {}".format(birthday) + str(birthday_ending) + '!'
12 changes: 8 additions & 4 deletions github.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ def print_user_repository_names():
# like 'Hackbright-Curriculum: Exercises for the Hackbright Academy Fellowship Program'

repos = github_api_response()

number = 0
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']
#print repo
#print number
for k, v in repo.iteritems():
print str(k) + ": " + str(repo[k])
#number +=1



if __name__=="__main__":
print_user_repository_names()
print_user_repository_names()
12 changes: 5 additions & 7 deletions halloween.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# I can't be bothered to think of a Hallowe'en costume so
# can you help me generate one randomly?


import random
nouns = []
adjectives = []

Expand All @@ -19,24 +19,22 @@
def generate_costume():

# pick something random from the nouns and adjectives list

noun = "lazy"
adj = "person"
noun = random.choice(nouns)
adj = random.choice(adjectives)

return (noun, adj)


while True:
(noun, adjective) = generate_costume()

print "You go dressed as a {} {} to the party."
print "You go dressed as a " + adjective + " " + noun + " to the party."

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
4 changes: 1 addition & 3 deletions icecream.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@
my_faves = ['mint', 'caramel']


for item in my_list:
if my_faves:
for item in my_faves:
print "I like {}".format(item)

20 changes: 13 additions & 7 deletions keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@
'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:
if position >= total_cats:
break

print get_cat_and_instrument(position)
position += 1
print get_cat_and_instrument(position)
position += 1

# Could you do the assignment of cats and instruments any other ways?
# Could you do the assignment of cats and instruments any other ways?
#python dict

cats_instruments = {
'Grizabella': 'keyboard',
'Rum Tum Tugger': 'cello'
}
40 changes: 25 additions & 15 deletions vacation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
'snow': 'skiing'
}

best_spot = {
'snow': 'Tahoe',
'wind': 'Hawaii',
'rain': 'New York',
'sun': 'Mexico'
}

def best_vacation_spot(weather_type):
# Look at the weather type and return the vacation spot that
Expand All @@ -32,39 +38,43 @@ def best_vacation_spot(weather_type):
# wind = Hawaii
# rain = New York
# sun = Mexico

return "Stay at home"
if weather_type in best_spot:
return best_spot[weather_type]
else:
return "Stay at home"


def vacation_activity(weather_type):
def activity(weather_type):
# Look up the vacation activity from activities
# and return just the activity itself
print activity
return activities[weather_type]


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:
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_type = weather_patterns[season]
# get the best vacation spot for that type
vacation_spot = best_vacation_spot(weather_type)
# get the best vacation activity for that type
vacation_activity = activity(weather_type)

# look up the weather type for that season
weather = weather_patterns[season]
print "You should travel to {}, where you can spend your time {}!".format(vacation_spot, vacation_activity)

# get the best vacation spot for that type
best_vacation_spot(weather_type)

# get the best vacation activity for that type
vacation_activity(weather_type)
def main():
print "Welcome to the Vacation-o-Matic!"

print "You should travel to {}, where you can spend your time {}!".format(vacation_spot, vacation_activity)


def main():
print "Welcome to the Vacation-o-Matic!"


if __name__=="__main__":
main()
main()
get_my_vacation()