Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submitting Fixed Code #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
25 changes: 20 additions & 5 deletions birthday.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime

# A dictionary of number endings
number_endings = {
1: 'st',
2: 'nd',
Expand All @@ -18,17 +19,31 @@
ending = 'th'

if todays_day < 10 or todays_day > 20:
# x % y (mod) will give the remainder when x is divided by y
# x % y (modulus) 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'
ending = number_endings[number]
print("Today is the {0}{1}".format(todays_day, ending))
else:
print ("Today is the {0}{1}".format(todays_day, ending))

# make this print ending, not 'th'
print "Today is the {}th".format(todays_day)
else:
print ("Today is the {}th".format(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)
if birthday < 10 or birthday > 20:
number = birthday % 10
if number in number_endings:
ending = number_endings[number]
print("Your birthday is on the {0}{1}".format(birthday, ending))
else:
print("Your birthday is on the {0}{1}".format(birthday, ending))
else:
print("Your birthday is on the {}th!".format(birthday))
6 changes: 3 additions & 3 deletions github.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def github_api_response():


def print_user_repository_names():

# I just want to print out the names and descriptions of the repositories..
# like 'Hackbright-Curriculum: Exercises for the Hackbright Academy Fellowship Program'

Expand All @@ -20,8 +19,9 @@ 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']+ ": " ,
print repo['description']


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

from random import randint

nouns = []
adjectives = []
Expand All @@ -15,28 +15,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"

return (noun, adj)
noun = nouns[randint(1, len(nouns)-1)]
adj = adjectives[randint(1, len(adjectives)-1)]
return (adj, noun)


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

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

(adjective, noun) = generate_costume()
print("You go dressed as a {0} {1} to the party.".format(adjective, 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("OK, I will choose another costume. Hold on...")
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:
print "I like {}".format(item)
for fave in my_faves:
print "I like %s" % fave

20 changes: 11 additions & 9 deletions keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
'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:
print(get_cat_and_instrument(position))
position += 1
else:
break

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?
for index, cat in enumerate(cats):
print(get_cat_and_instrument(index))
44 changes: 28 additions & 16 deletions vacation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,50 @@ def best_vacation_spot(weather_type):
# wind = Hawaii
# rain = New York
# sun = Mexico

return "Stay at home"
if weather_type == "snow":
spot = vacation_spots.index('Tahoe')
return vacation_spots[spot]
elif weather_type == "wind":
spot = vacation_spots.index('Hawaii')
return vacation_spots[spot]
elif weather_type == "rain":
spot = vacation_spots.index('New York')
return vacation_spots[spot]
elif weather_type == "sun":
spot = vacation_spots.index('Mexico')
return vacation_spots[spot]
else:
return "Stay at home"


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? ")

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

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

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

print "You should travel to {}, where you can spend your time {}!".format(vacation_spot, vacation_activity)
# get the best vacation activity for that type
activity = vacation_activity(weather)
print("You should travel to {}, where you can spend your time {}!".format(spot, activity))


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


if __name__=="__main__":
Expand Down