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
43 changes: 33 additions & 10 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,45 @@
# but beware! 11 => 11th, 21 => 21st, 31 => 31st

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

todays_day = 9

ending = 'th'
number = 0

#for date,ending in number_endings.items():
# print "%d has ending %s" % (date, ending)

print todays_day

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)
if number in number_endings:
ending = number_endings[number]
# print "Today is the {}".format(todays_day)+"%s" % ending
# % number_ending

# if todays_day >= 10 or todays_day <= 20:

print "Today is the {}".format(todays_day)+"%s" % ending



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)
ending = 'th'


if birthday < 10 or birthday > 20:
number = birthday % 10

if number in number_endings:
ending = number_endings[number]
# print "Birthday is the {}".format(birthday)+"%s" % ending
# % number_ending

# if todays_day >= 10 or todays_day <= 20:

print "Birthday is the {}".format(birthday)+"%s" % ending
15 changes: 10 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 @@ -10,33 +11,37 @@
# so we call strip() before adding it to our nouns list.
for line in f:
nouns.append(line.strip())
# print nouns

with open('descriptors.txt') as f:
for line in f:
adjectives.append(line.strip())
# print adjectives


def generate_costume():

# pick something random from the nouns and adjectives list

noun = "lazy"
adj = "person"
noun = nouns[random.randrange(len(nouns))]
adj = adjectives[random.randrange(len(adjectives))]
# print "%s" % noun
# print "%s" % adj

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
13 changes: 9 additions & 4 deletions icecream.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
'cookie dough', 'vanilla', 'lemon']
my_faves = ['mint', 'caramel']


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

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




19 changes: 10 additions & 9 deletions keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
'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

get_cat_and_instrument(position)

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?
42 changes: 30 additions & 12 deletions vacation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# Start at the bottom and work upwards.


vacation_spots = ['Tahoe', 'Hawaii', 'New York', 'Mexico']

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

weather_patterns = {
Expand All @@ -23,6 +21,13 @@
'snow': 'skiing'
}

vacation_spots = {
'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 +37,52 @@ def best_vacation_spot(weather_type):
# wind = Hawaii
# rain = New York
# sun = Mexico

vacation_spot = vacation_spots[weather_type]
print vacation_spot
return vacation_spot

return "Stay at home"

#return "Stay at home"


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


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:
print "Sorry, that isn't a season. I can't help you."

# look up the weather type for that season
weather = weather_patterns[season]

else:
weather_type = weather_patterns[season]

print weather_type


# 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)

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, vacation_activity)
print vacation_spot
print vacation_activity

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


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