I A Review of Function Creation
i. BeFOR We Begin 1/13
names = ["Adam","Alex","Mariah","Martine","Columbus"] for naam in names: print naam
ii. This is KEY! 2/13
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 web in webster: print webster[web]
iii. Control Flow and Looping 3/13
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] for item in a: if item % 2 == 0: print item
iv. Lists + Functions 4/13
# Write your function below! def fizz_count(x): count = 0 for item in x: if item == 'fizz': count = count +1 return count
v. String Looping 5/13
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
II Owning a Store
i. Your Own Store! 6/13
prices = { 'banana' : 4, 'apple' : 2, 'orange' : 1.5, 'pear' : 3 }
ii. Investing in Stock 7/13
prices = { 'banana' : 4, 'apple' : 2, 'orange' : 1.5, 'pear' : 3 } stock = { 'banana' : 6, 'apple' : 0, 'orange' : 32, 'pear' : 15 }
iii. Keeping Track of the Produce 8/13
prices = { 'banana' : 4, 'apple' : 2, 'orange' : 1.5, 'pear' : 3 } stock = { 'banana' : 6, 'apple' : 0, 'orange' : 32, 'pear' : 15 } for fruit in prices: print fruit print "price: %s" % prices[fruit] print "stock: %s" % stock[fruit]
iv. Something of Value 9/13
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
III Shopping trip!
i. Shopping at the Market 10/13
groceries = ['banana','orange','apple']
ii. Making a Purchase 11/13
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): total = 0 for x in food: total += prices[x] return total
iii. Stocking Out 12/13
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): total = 0 for x in food: if stock[x] != 0: total += prices[x] stock[x] = stock[x] - 1 return total
iv. Let’s Check Out! 13/13
>Save and Submit
I just want to thank you from the bottom of my heart! Your work is wonderful!!!
LikeLike
you saved my life thank you so much
LikeLike
çok teşekkür ederim,eline sağlık.
LikeLike
oh my god thanks so much
LikeLike
Thank you soooo much sunakshi you are the best I love you and where you are right now I congratulate you and thank you for helping others and considerin that they need help thanks xx and you are beautiful you saved me from doing wrong coding xx
LikeLike