Tuesday, October 14, 2014

Day 140

Python at CodeCademy. Worked on Python tutorial 8 of 13, A Day at the Supermarket: Keeping Track of the Produce! Worked on printing out.

Code used:
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}

for key in prices:
    print key
    print "price: %s" % prices[key]
    print "stock: %s" % stock[key]

Interaction for this code:
orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0

Day 139

Python at CodeCademy. Worked on Python tutorial 7 of 13, A Day at the Supermarket: Your Own Store! Worked on creating another dictionary .

Code used:
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}

There was no interaction for this code:

Day 138

Python at CodeCademy. Worked on Python tutorial 6 of 13, A Day at the Supermarket: Your Own Store! Worked on creating a new dictionary .

Code used:
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

There was no interaction for this code:

Sunday, October 12, 2014

Day 137

Python at CodeCademy. Worked on Python tutorial 5 of 13, A Day at the Supermarket: String Looping! Worked on looping through strings, like lists.

Code used:
for letter in "Codecademy":
    print letter

print
print

word = "Programming is fun!"

for letter in word:

    if letter == "i":
        print letter

Interaction for this code:

C
o
d
e
c
a
d
e
m
y

i
i

Day 136

Python at CodeCademy. Worked on Python tutorial 4 of 13, A Day at the Supermarket: Lists + Functions! Worked on using lists as inputs to perform various operations on those lists.

Code used:
def fizz_count(x):
    count = 0
    for item in x:
        if item == "fizz":
            count = count + 1
    return count

There was no interaction for this code:

Friday, October 10, 2014

Day 135

Python at CodeCademy. Worked on Python tutorial 3 of 13, A Day at the Supermarket: Control Flow and Looping! Worked on performing different actions depending on the particular item in the list, while looping.

Code used:
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

for number in a:
    if number % 2 == 0:
        print number


Interaction for this code:
0
2
4
6
8
10
12

Day 134

Python at CodeCademy. Worked on Python tutorial 2 of 13, A Day at the Supermarket: This is KEY! Worked on using a for loop on a dictionary to loop through its keys.

Code used:
webster = {
"Aardvark" : "A star of a popular children's cartoon show.",
    "Baa" : "The sound a goat makes.",
    "Carpet": "Goes on the floor.",
    "Dab": "A small amount."
}
for key in webster:
    print webster[key]


Interaction for this code:
A star of a popular children's cartoon show.
The sound a goat makes.
Goes on the floor.
A small amount.

Wednesday, October 8, 2014

Day 133

Python at CodeCademy. Worked on Python tutorial 1 of 13, A Day at the Supermarket: BeFOR We Begin! Worked on going over the for loop in terms of how it relates to lists and dictionaries.

code uses:
names = ["Adam","Alex","Mariah","Martine","Columbus"]
for x in names:
    print x

Interaction for this code:
Adam
Alex
Mariah
Martine
Columbus

Tuesday, October 7, 2014

Day 132

Spent some time reading about C# and Objective C. Figured I would do a little more Python in the meantime. Python at CodeCademy. Worked on Python tutorial 14 of 14, Python Lists and Dictionaries: Remove a Few Things! Worked on removing something from a list and putting it all together.

The code used:inventory = {
    'gold' : 500,
    'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key
    'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']
}

# Adding a key 'burlap bag' and assigning a list to it
inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']

# Sorting the list found under the key 'pouch'
inventory['pouch'].sort()

inventory['pocket'] = ['seashell', 'strange berry', 'lint']
inventory['backpack'].sort()
inventory['backpack'].remove('dagger')
inventory['gold'] += 50

There was no interaction for this code: