# 01 BeFOR We Begin
names = ["Adam","Alex","Mariah","Martine","Columbus"]
for e in names:
print (e)
Adam Alex Mariah Martine Columbus
# 02 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 k in webster:
print (webster[k])
A small amount. The sound a goat makes. Goes on the floor. A star of a popular children's cartoon show.
# 03 Control Flow and Looping
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
for num in a:
if num % 2 == 0:
print (num)
0 2 4 6 8 10 12
# 04 Lists plus Functions
# Write your function below!
def fizz_count(x):
count = 0
for e in x:
if e == 'fizz':
count += 1
return count
# 05 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)
C o d e c a d e m y i i
# 06 Your Own Store
prices = {"banana" : 4, "apple" : 2, "orange" : 1.5, "pear" : 3}
# 07 Investing in Stock
stock = {"banana" : 6, "apple" : 0, "orange" : 32, "pear" : 15}
# 08 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 fruit in stock:
print (fruit)
print ("price: " + str(prices[fruit]))
print ("stock: " + str(stock[fruit]))
pear price: 3 stock: 15 orange price: 1.5 stock: 32 banana price: 4 stock: 6 apple price: 2 stock: 0
# 09 Something of Value
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
income = 0.0
for fruit in prices:
income += prices[fruit] * stock[fruit]
print (income)
117.0
# 10 Shopping at the Market
groceries = ["banana", "orange", "apple"]
# 11 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
}
# Write your code below!
def compute_bill(food):
costs = 0.0
for item in food:
costs += prices[item]
return costs
# 12 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
}
# Write your code below!
def compute_bill(food):
costs = 0.0
for item in food:
if stock[item] > 0:
stock[item] -= 1
costs += prices[item]
return costs
print (compute_bill(['apple', 'pear', 'pear', 'orange']))
7.5
# 13 Lets 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
}
# Write your code below!
def compute_bill(food):
costs = 0.0
for item in food:
if stock[item] > 0:
stock[item] -= 1
costs += prices[item]
return costs