Today’s assignment was to complete “A Day At the Supermarket!” on codeacademy. This lab was not very hard and was easy to follow. This lab was based on the concept of dictionaries and that every item had a key to it.

In this screenshot I looped through the list by using a for loop and printed each name inside the list.

In this screenshot, I printed out the keys in the dictionary. I used the for loop to access the dictionary. Then printed the keys by typing the name of the dictionary inside brackets put in x for each item in the dictionary.

In this screenshot, I printed out only the even numbers in a list. I used the for loop and looped through the list with the condition that if x % 2 ==0.

In this screenshot, it would count the number of times fizz appears in a list. It would increment if the string “fizz” shows up in a list.

 

 

 

Here, I simply created a dictionary named “prices” and added a key for each item. Dictionaries are written with a variable followed by an equal sign and then surrounded by curly braces.

I created the stock dictionary next. With the following items.

I used a for loop to loop through the prices dictionary to print out the following information: (the name of the fruit, it’s price, and the amount in stock). I first printed “key” which is the first item in prices without the number (key). Then printed out prices[key] which accessed the number of the fruit. Then printed out its stock using stock[key].

I found the total if I would’ve sold all the fruit. I declared a variable named “total” and set it equal to 0. Then used a for loop to loop through prices. I printed out the price for the amount of stock for a fruit (print prices[key] * stock[key]). Assigned total to total + prices [key] * stock[key]. Then I printed the total out of the loop.

In this screenshot, I created a list named groceries with the items banana, orange, and apple.

In this screenshot, I created the function named “compute_ball” that took the argument of food. I created a variable inside the function named “total” and assigned it to the value of 0. I used a for loop to loop through “food” and assigned total to total + prices[item]. Then returned the total outside of the loop.

In this screenshot, I determined if the stock had nothing inside it (if stock[item] > 0:), if the fruit had no stock then I would earn no money from it. For the fruits with stock, I added the prices and subtracted 1 from the stock count.