Tuesday, June 11, 2013

Grocery Store Project

As you go deep in programing, it become very hard or harder.
This project, going through or learning it was very difficult for me but with the help of your able Instructor "Zane Cochran", I was able to learned it.
These are few codes below.
"""
Learning Python
Lesson 6 : List & Dictionaries

Simple programming exercises from Codecademy
"""


# Exercise 0 : BeFOR We Begin
"""
    Use a for loop to print out all of the elements in the list names.
"""

names = ["Adam","Alex","Mariah","Martine","Columbus"]

for word in names:
    print word

   
# Exercise 1 : This is KEY!
"""
    Use a for loop to go through the webster dictionary
    and print out all of the definitions.
"""

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 word in webster:
    print webster[word]

# Exercise 2 : Control Flow and Looping
"""
    Loop through list a and only print out the even numbers.
"""
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

for allnumbers in a:
    if allnumbers %2 == 0:
       print allnumbers
   
# Exercise 3 : Lists & Functions
"""
    Write a function called fizz_count that takes a list x
    as input and returns the count of the string "fizz" in
    that lise. For example,

    fizz_count(["fizz", "buzz", "fizz"]) should return 2.

    Then give your fizz_count the argument sample and see what it returns:
    print fizz_count(sample)
   
"""
sample = ["fizz", "buzz", "fizz", "buzz", "fizz", "fizz", "fizz"]


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



Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>>
Adam
Alex
Mariah
Martine
Columbus
A star of a popular children's cartoon show.
Goes on the floor.
A small amount.
The sound a goat makes.
0
2
4
6
8
10
12
5
>>>
Adam
Alex
Mariah
Martine
Columbus
A star of a popular children's cartoon show.
Goes on the floor.
A small amount.
The sound a goat makes.
0
2
4
6
8
10
12

"""
Learning Python
Lesson 6 : List & Dictionaries
Grocery Store Project

Simple programming exercises from Codecademy
"""


# Exercise 0 : Your Own Store!
"""
    Create a dictionary called prices
    Give it the following key/value pairs:

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


# Exercise 1 : Investing in Stock
"""
    Create a dictionary called stock
    Give it the following key/value pairs:

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




# Exercise 2 : Keeping Track of the Produce 
"""
    Use a for loop to print out information about every item in your store

    Print the answer in the following format:

    item
    "price: x"
    "stock: x"

    So when you print out the data for apples, print out:

    apple
    price: 2
    stock: 0

    Each of these values should be in a different print statement.
    Remember to convert numbers to strings before trying to combine them.
"""
for item in stock:
    print item
    print "price: %s" % prices[item]
    print "stock: %s" % stock [item]
   

# Exercise 3 : Something of Value  
"""
    Use a for loop to determine how much money you would make
    if you sold all the food you had in stock.

    Print out the result.
"""
total=0
for item in stock:
    sales = prices[item]* stock[item]
    total = total + sales
   
print total

Adam
Alex
Mariah
Martine
Columbus
A star of a popular children's cartoon show.
Goes on the floor.
A small amount.
The sound a goat makes.
0
2
4
6
8
10
12
fizz
buzz
fizz
buzz
fizz
fizz
fizz
None
>>>
Adam
Alex
Mariah
Martine
Columbus
A star of a popular children's cartoon show.
Goes on the floor.
A small amount.
The sound a goat makes.
0
2
4
6
8
10
12
5
>>>
Adam
Alex
Mariah
Martine
Columbus
A star of a popular children's cartoon show.
Goes on the floor.
A small amount.
The sound a goat makes.
0
2
4
6
8
10
12
1
2
3
4
5
5
>>>
Adam
Alex
Mariah
Martine
Columbus
A star of a popular children's cartoon show.
Goes on the floor.
A small amount.
The sound a goat makes.
0
2
4
6
8
10
12
fizz
fizz
fizz
fizz
fizz
5
>>>
Adam
Alex
Mariah
Martine
Columbus
A star of a popular children's cartoon show.
Goes on the floor.
A small amount.
The sound a goat makes.
0
2
4
6
8
10
12
5
>>>
>>>
orange
pear
banana
apple

orange
1.5
32
pear
3
15
banana
4
6
apple
2
0
>>>
orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0

>>>
orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
117.0
>

No comments:

Post a Comment