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
51 changes: 28 additions & 23 deletions birthday.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
from datetime import datetime

number_endings = {
1: 'st',
2: 'nd',
3: 'rd'
}
def right_ending(todays_day):

today = datetime.now()
todays_day = today.day
number_endings = {
1: 'st',
2: 'nd',
3: 'rd'
}

# get the right ending, e.g. 1 => 1st, 2 => 2nd
# but beware! 11 => 11th, 21 => 21st, 31 => 31st

# get the right ending, e.g. 1 => 1st, 2 => 2nd
# but beware! 11 => 11th, 21 => 21st, 31 => 31st
# test your code by forcing todays_day to be something different
# todays_day = 11

# test your code by forcing todays_day to be something different
# todays_day = 11
ending = 'th'

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:
ending = str(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:
today = datetime.now()
todays_day = today.day

# make this print ending, not 'th'
print "Today is the {}th".format(todays_day)
x = right_ending(todays_day)
print "Today is the "+str(todays_day)+x+".\n"

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

x = right_ending(int(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)+x+".\n"
9 changes: 6 additions & 3 deletions github.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ 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']+": "+repo['description']
else:
print repo['name']+": No description"



if __name__=="__main__":
print_user_repository_names()
print_user_repository_names()
11 changes: 6 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

nouns = []
adjectives = []
Expand All @@ -20,23 +21,23 @@ 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(noun, adjective)

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 == "yes" or happy == "y":
exit()
else:
print "OK, I will choose another costume. Hold on..."
print
print
5 changes: 2 additions & 3 deletions icecream.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
my_faves = ['mint', 'caramel']


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

17 changes: 8 additions & 9 deletions keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@
'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:
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?
43 changes: 24 additions & 19 deletions vacation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,53 @@
'snow': 'skiing'
}

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


def best_vacation_spot(weather_type):
def best_vacation_spot(weather):
# 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"
spot = spots_by_weather[weather]
return spot


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_travel = raw_input("What season do you want to travel? ")

# check if season is in the seasons list
if not seasons:
if season_travel 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_travel]

# 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)
# get the best vacation spot for that type
spot = best_vacation_spot(weather)

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

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!"
print "You should travel to {}, where you can spend your time {}!".format(spot, activity)


if __name__=="__main__":
main()
print "Welcome to the Vacation-o-Matic!"
get_my_vacation()