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
25 changes: 14 additions & 11 deletions birthday.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@
# test your code by forcing todays_day to be something different
# todays_day = 11

ending = 'th'
def find_ending(day):
ending = 'th'
if day < 10 or day > 20:
# x % y (mod) will give the remainder when x is divided by y
# -- but x needs to be an integer!
number = 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:
ending = number_endings[number]
return ending

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:

# make this print ending, not 'th'
print "Today is the {}th".format(todays_day)
print "Today is the " + str(todays_day) + find_ending(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)
print "Your birthday is on the " + str(birthday) + find_ending(birthday) + "!"
3 changes: 1 addition & 2 deletions github.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ 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']
print repo['name'] + " -> " + repo['description']


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

import random, site

nouns = []
adjectives = []
Expand All @@ -15,23 +16,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"
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 {} {} to the party.".format(adjective, noun)

happy = raw_input("Are you happy with this choice? ")
happy = raw_input("Are you happy with this choice? ").lower().startswith("y")

# Check if the user typed something like 'yes' or 'y' and
# quit the program if they are happy.
Expand Down
4 changes: 2 additions & 2 deletions icecream.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
my_faves = ['mint', 'caramel']


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

19 changes: 11 additions & 8 deletions keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
instruments = ['keyboard', 'cello', 'bass', 'flute', 'pipe', 'piano',
'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

print get_cat_and_instrument(position)
position += 1
while True:
if position >= total_cats:
break

print get_cat_and_instrument(position)
position += 1

# Could you do the assignment of cats and instruments any other ways?
30 changes: 15 additions & 15 deletions vacation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
# Hint:
# Start at the bottom and work upwards.

import site

vacation_spots = ['Tahoe', 'Hawaii', 'New York', 'Mexico']
vacation_spots = {
'snow': 'Tahoe',
'wind': 'Hawaii',
'rain': 'New York',
'sun': 'Mexico'
}

seasons = ['spring', 'summer', 'fall', 'winter']

Expand All @@ -25,45 +31,39 @@


def best_vacation_spot(weather_type):
# Look at the weather type and return the vacation spot that
# is the best for that weather.
# You can use this mapping:
# snow = Tahoe
# wind = Hawaii
# rain = New York
# sun = Mexico

return "Stay at home"
return vacation_spots[weather_type]


def vacation_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."
exit()

# 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)
vacation_spot = best_vacation_spot(weather)

# get the best vacation activity for that type
vacation_activity(weather_type)
activity = vacation_activity(weather)

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


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


if __name__=="__main__":
Expand Down