Codecademy Python Answers A Day at the Super Market

codecademy-day-at-super-market-answers

A Day At the Super Market 1/13 – BeFor We Begin

names = ["Adam","Alex","Mariah","Martine","Columbus"]
for i in names:
    print i

A Day At the Super Market 2/13 – This is Key

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."
}

# Add your code below!
for i in webster:
    print webster[i]

A Day At the Super Market 3/13 – Control Flow and Looping

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

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

A Day At the Super Market 4/13 – Lists + Functions

# Write your function below!
def fizz_count(x):
    count = 0
    for i in x:
        if i=="fizz":
            count+=1
    return count

A Day At the Super Market 5/13 – String Looping

for letter in "Codecademy":
    print letter
    
# Empty lines to make the output pretty
print
print

word = "Programming is fun!"

for letter in word:
    # Only print out the letter i
    if letter == "i":
        print letter

A Day At the Super Market 6/13 – Your Own Store

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

A Day At the Super Market 7/13 – Investing in Stock

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

A Day At the Super Market 8/13 – Keeping Track of the produce

stock = {"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
for item in prices:
    print item
    print "price: " + str(prices[item])
    print "stock: " + str(stock[item])

A Day At the Super Market 9/13 – Something of Value

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]

total=0
for key in prices:
    total=total+prices[key]*stock[key]
    print total

A Day At the Super Market 10/13 -Shopping At The Market

groceries = ["banana","orange","apple"]

A Day At the Super Market 11/13 – Making a Purchase

shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}
food = shopping_list
# Write your code below!
def compute_bill(food):
    total=0
    for item in food:
            total += prices[item]
    return total

A Day At the Super Market 12/13 – Stocking Out

shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}
food = shopping_list
# Write your code below!
def compute_bill(food):
    total=0
    for item in food:
        if stock[item]>0:
            total += prices[item]
            stock[item]-=1
    return total

A Day At the Super Market 13/13 – Let’s Check Out

shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}
food = shopping_list
# Write your code below!
def compute_bill(food):
    total=0
    for item in food:
        if stock[item]>0:
            total += prices[item]
            stock[item]-=1
    return total

Leave a Reply

Your email address will not be published. Required fields are marked *