Thursday, August 14, 2014

Day 131

Python at CodeCademy. Worked on Python tutorial 13 of 14, Python Lists and Dictionaries: Remove a Few Things! Worked on removing something from a list.

The code used:
backpack = ['xylophone', 'dagger', 'tent', 'bread loaf']
backpack.remove("dagger")

There was no interaction for this code:

Wednesday, August 13, 2014

Day 130

Python at CodeCademy. Worked on Python tutorial 12 of 14, Python Lists and Dictionaries: Changing Your Mind! Worked on changing dictionarys.

The code used:
# key - animal_name : value - location 
zoo_animals = { 'Unicorn' : 'Cotton Candy House',
'Sloth' : 'Rainforest Exhibit',
'Bengal Tiger' : 'Jungle House',
'Atlantic Puffin' : 'Arctic Exhibit',
'Rockhopper Penguin' : 'Arctic Exhibit'}

del zoo_animals['Unicorn']

del zoo_animals['Sloth']
del zoo_animals['Bengal Tiger']

zoo_animals['Rockhopper Penguin'] = "Ice Exhibit"

print zoo_animals

The interaction for this code:
{'Atlantic Puffin': 'Arctic Exhibit', 'Rockhopper Penguin': 'Ice Exhibit'}

Tuesday, August 12, 2014

Day 129

Python at CodeCademy. Worked on Python tutorial 11 of 14, Python Lists and Dictionaries: New Entries! Worked on how dictionary lists are "mutable".

The code used:
menu = {}
menu['Chicken Alfredo'] = 14.50
print menu['Chicken Alfredo']

menu['Pot Sticker'] = 11.25 

menu['Meat Fingers'] = 8

menu['Pizza'] = 30

print "There are " + str(len(menu)) + " items on the menu."
print menu

The interaction for this code:
14.5
There are 4 items on the menu.
{'Chicken Alfredo': 14.5, 'Pot Sticker': 11.25, 'Pizza': 30, 'Meat Fingers': 8}

Monday, August 11, 2014

Day 128

Python at CodeCademy. Worked on Python tutorial 10 of 14, Python Lists and Dictionaries: This Next Part is Key! Worked on dictionary and accessing values by looking up a key.

The code used:
residents = {'Puffin' : 104, 'Sloth' : 105, 'Burmese Python' : 106}

print residents['Puffin'] # Prints Puffin's room number
print residents['Sloth']
print residents['Burmese Python']

The interaction for this code:
104
105
106

Sunday, August 10, 2014

Day 127

Python at CodeCademy. Worked on Python tutorial 9 of 14, Python Lists and Dictionaries: More with 'for'! Worked on sort.

The code used:
start_list = [5, 3, 1, 2, 4]
square_list = []

for number in start_list:
    square_list.append(number ** 2)
square_list.sort()# Your code here!

print square_list

The interaction for this code:
[1, 4, 9, 16, 25]

Saturday, August 9, 2014

Day 126

Python at CodeCademy. Worked on Python tutorial 8 of 14, Python Lists and Dictionaries: For One and All! Worked on for-loop.

The code used:
my_list = [1,9,3,8,5,7]

for number in my_list:
    print number * 2

The interaction for this code:
2
18
6
16
10
14

Friday, August 8, 2014

Day 125

Python at CodeCademy. Worked on Python tutorial 7 of 14, Python Lists and Dictionaries: Maintaining Order! Worked on search for an item in a list.

The code used:
animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index = animals.index("duck")
animals.insert(duck_index, "cobra")

The interaction for this code:
['aardvark', 'badger', 'cobra', 'duck', 'emu', 'fennec fox']

Thursday, August 7, 2014

Day 124

Python at CodeCademy. Worked on Python tutorial 6 of 14, Python Lists and Dictionaries: Slicing Lists and Strings! Worked on slicing a string exactly like a list.

The code used:
animals = "catdogfrog"
cat  = animals[:3]   # The first three characters of animals
dog  = animals[3:6]   # The fourth through sixth characters
frog = animals[6:]   # From the seventh character to the end

There was no interaction for this code:

Wednesday, August 6, 2014

Day 123

Python at CodeCademy. Worked on Python tutorial 5 of 14, Python Lists and Dictionaries: List Slicing! Worked on accessing a portion of a list..

The code used:
suitcase = ["sunglasses", "hat", "passport", "laptop", "suit", "shoes"]
first  = suitcase[0:2]  # The first and second items (index zero and one)
middle = suitcase[2:4]  # Third and fourth items (index two and three)
last   = suitcase[4:6]  # The last two items (index four and five)

There was no interaction for this code:

Tuesday, August 5, 2014

Day 122

Python at CodeCademy. Worked on Python tutorial 4 of 14, Python Lists and Dictionaries: Late Arrivals & List Length! Worked on adding items to the end of a list.

The code used:
suitcase = [] 
suitcase.append("sunglasses")

# Your code here!
suitcase.append('hat')
suitcase.append('shirt')
suitcase.append('shorts')

list_length = len(suitcase) # Set this to the length of suitcase

print "There are %d items in the suitcase." % (list_length)
print suitcase

The interaction for this code:
There are 4 items in the suitcase.
['sunglasses', 'hat', 'shirt', 'shorts']

Monday, August 4, 2014

Day 121

Python at CodeCademy. Worked on Python tutorial 3 of 14, Python Lists and Dictionaries: New Neighbors! Worked on an assignment statement that replaces the item that currently holds the value "tiger" with another animal (as a string).

The code used:
zoo_animals = ["pangolin", "cassowary", "sloth", "tiger"]
# Last night our zoo's sloth brutally attacked 
#the poor tiger and ate it whole.

# The ferocious sloth has been replaced by a friendly hyena.
zoo_animals[2] = "hyena"

# What shall fill the void left by our dear departed tiger?
zoo_animals[3] = "lion"

There was no interaction for this code:

Sunday, August 3, 2014

Day 120

Python at CodeCademy. Worked on Python tutorial 2 of 14, Python Lists and Dictionaries: Access by Index! Learned to access an individual item on a list with its index.

The code used:
numbers = [5, 6, 7, 8]

print "Adding the numbers at indices 0 and 2..."
print numbers[0] + numbers[2]
print "Adding the numbers at indices 1 and 3..."
print numbers[1] + numbers[3]

The interaction for this code:
Adding the numbers at indices 0 and 2...
12
Adding the numbers at indices 1 and 3...
14

Saturday, August 2, 2014

Day 119

Python at CodeCademy. Worked on Python tutorial 1 of 14, Python Lists and Dictionaries: Introduction to Lists! Intro to lists, added an item to an existing list.

The code used:
zoo_animals = ["pangolin", "cassowary", "sloth", "elephant", ];

if len(zoo_animals) > 3:
print "The first animal at the zoo is the " + zoo_animals[0]
print "The second animal at the zoo is the " + zoo_animals[1]
print "The third animal at the zoo is the " + zoo_animals[2]
print "The fourth animal at the zoo is the " + zoo_animals[3]

The interaction for this code:
The first animal at the zoo is the pangolin
The second animal at the zoo is the cassowary
The third animal at the zoo is the sloth
The fourth animal at the zoo is the elephant

Friday, August 1, 2014

Day 118

Python at CodeCademy. Worked on Python tutorial 7 of 7, Taking a Vacation: Hey, You Never Know!
Finished tutorial, worked with more defining functions that accept strings as an arguments and added one last one.

The code used:
def hotel_cost(nights):
    return 140 * nights
    
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    elif city == "Pittsburgh":
        return 222
    elif city == "Los Angeles":
        return 475
        
def rental_car_cost(days):
    if days >= 7:
        return days * 40 - 50
    elif days >= 3:
        return days * 40 - 20
    else:
        return days * 40
        
def trip_cost(city, days, spending_money):
    return plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(days) + spending_money
    
print trip_cost("Los Angeles",5,600)

The interaction for this code:
1955