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
30 changes: 16 additions & 14 deletions birthday.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
number_endings = {
1: 'st',
2: 'nd',
3: 'rd'
3: 'rd',
}

today = datetime.now()
Expand All @@ -13,22 +13,24 @@
# but beware! 11 => 11th, 21 => 21st, 31 => 31st

# test your code by forcing todays_day to be something different
# todays_day = 11
# todays_day = 1

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 set_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]
# make this print ending, not 'th'
return ending

# make this print ending, not 'th'
print "Today is the {}th".format(todays_day)
print "Today is the {0}{1}".format(todays_day, set_ending(todays_day))

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 {0}{1}!".format(birthday, set_ending(birthday))
9 changes: 4 additions & 5 deletions github.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import json


def github_api_response():
with open('github.json') as f:
github = json.loads(f.read())
return github


def print_user_repository_names():

# I just want to print out the names and descriptions of the repositories..
Expand All @@ -20,9 +20,8 @@ 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__":
print_user_repository_names()
if __name__ == "__main__":
print_user_repository_names()
14 changes: 7 additions & 7 deletions halloween.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@


def generate_costume():

import random
# 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()
(noun, adj) = generate_costume()

print "You go dressed as a {} {} to the party."
print "You go dressed as a {} {} to the party.".format(adj, 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
7 changes: 3 additions & 4 deletions icecream.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

all_flavors = ['chocolate', 'mint', 'strawberry', 'caramel', 'pecan',
'cookie dough', 'vanilla', 'lemon']
my_faves = ['mint', 'caramel']
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)

40 changes: 30 additions & 10 deletions keyboard.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
# I had this great script, but my keyboard broke and I can't indent
# any of my code. Can you indent it for me?

import random

cats = ['Grizabella', 'Rum Tum Tugger', 'Demeter', 'Munkustrap',
'Mistoffelees', 'Macavity', 'Rumpleteazer', 'Mungo Jerry', 'Skimbleshanks']
'Mistoffelees', 'Macavity', 'Rumpleteazer', 'Mungo Jerry',
'Skimbleshanks']

instruments = ['keyboard', 'cello', 'bass', 'flute', 'pipe', 'piano',
'violin', 'oboe', 'triangle']
'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

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

random.shuffle(cats)
random.shuffle(instruments)

print get_cat_and_instrument(position)
position += 1

# Could you do the assignment of cats and instruments any other ways?
def get_cat_and_instrument(position):
cat = cats[position]
instrument = instruments[position]
return "{} plays the {}".format(cat, instrument)

# Print out my cat orchestra one by one
position = 0

for item in cats:
print get_cat_and_instrument(position)
position += 1
4 changes: 3 additions & 1 deletion vacation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def best_vacation_spot(weather_type):
# rain = New York
# sun = Mexico



return "Stay at home"


Expand All @@ -47,7 +49,7 @@ 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."

# look up the weather type for that season
Expand Down