Lab Description:

This lab allows you to write codes using “for loops”, “dictionaries”, “list”, and “conditional statements” with the purpose of creating a code where you can calculate the price of items that you may purchase on the supermarket. But first, this lab show use how dictionaries work in python. In the first step we have to create a “for loop” where it test the membership of the list “names” and print each name. Second step, we also have to create a loop, however, it would test the membership of the dictionary “webster” and prints out all the definitions in this dictionary by typing “print webster[x]” where x can be any thing as long it is the variable use in the loop. The purpose of the x is to test every membership of the dictionary by being the key. Third step, we create a loop where it just print out the even numbers in a list by using the “if” statement and the operator “%” to see if the number is divisible by two. Fourth step, we create a function which calculates how many times the word “fizz” appears in a list which if the “if statement” is true, 1 is going to be added to the count variable. Fifth step, we see how iterations on loops work. Sixth step, we created a empty dictionary by setting a variable = “{}” and we later on added items between the brackets where the items are composed of keys, each key contains a value and each item is separated by comas. Seventh step we created another dictionary with the same keys as the previous one, but with different values. Eighth step, a for loop is created where the membership of the “prices” dictionary is tested. The first print in this loop allows the establishment of the key that is being tested, the second print allows to replace the “%s” with the value of the key and putted together with a string, same as the third print. You may be asking, why is the stock dictionary is in the loop when the loop is testing just the prices? Well, by having two dictionaries with the same keys, it allows the interchange of each dictionary in the loop as long as they have the same keys. Step nine, we multiply the value of the first dictionary with the value of the second and added them to a variable. Step 10, we created a list with some items. Step 11, we create a function which takes a parameter, in this function a loop is created where it adds the price of each item in the dictionary. Step 12, the change that is made to the loop is that is just going to add the price of does items that are greater than zero in supply, which this items are in the stock dictionary.

Step #1:

 

 

 

 

Step #2:

 

 

 

 

Step #3:

 

 

 

 

Step #4:

 

 

 

 

Step #5:

 

 

 

 

Step #6:

 

 

 

 

Step #7:

 

 

 

 

Step #8:

 

 

 

 

Step #9:

 

 

 

 

Step #10:

 

 

 

 

Step #11:

 

 

 

 

Step #12:

 

 

 

 

 

Step #13: