Reference no: EM133231238
Assignment - Computer Science Variable Creation Programming Question
Lab - Variables, types, and collections
Q1. Create a variable named dishes and use it to store a list of your 5 favorite dishes, in order of preference. Print this variable.
Q2. Using the data stored in the variable dishes, print a sentence that tells what is your first and fifth favorite dishes (e.g., Shish taouk is my favorite dish and stroganoff beef is my fifth favorite dish.).
Q3. Using the data stored in the variable dishes, create a new variable menu which maps (i.e., this would be a dictionary) the days of the week (key) with the dishes that you will eat (values) such that you eat your favorite meal on Monday, your second favorite meal on Tuesday, and so on. Print the variable menu.
Q4. Add two entries to your menu dictionary for Saturday and Sunday (with whatever dish you'd like).
Q5. If you wanted to know how many items you have in your list dishes, you could print len(dishes). Using this information, print a sentence like My list contains 23 dishes., where the number of dishes is the value returned by len(dishes)) (i.e., do not "hard code" the value 5; the printed value should update automatically if you were to add or remove items to the dishes list).
Q6. Do the same thing with the dictionary menu (i.e., print a sentence that says the number of items in menu).
Q7. list(menu.keys()) and list(menu.values() return lists of the keys (days of the week) and values (meals), respectively. Print the sentence This week, I will eat [shish taouk, pizza, ...]. listing the 7 meals contained in your dictionary menu.
Q8. Replace the meal you will eat on Wednesday with the meal you were planning to eat on Sunday. Then, delete the entry for Sunday in your dictionary and print the variable menu.
Q9. Create a dictionary variable_types that contains as key the name of your variables (i.e., dishes and menu) and as value their types. The type of a variable can be obtained by using type(my_variable) (to obtain the type of a variable named my_variable in this example). Print the dictionary variable_types.
Q10. Create a dictionary variables where the keys are the variable name (dishes and menu) and values are dictionaries. These "inner" dictionaries will have three keys: type, address, and content. The corresponding values should be the variable type (i.e., type(my_variable)), the variable address (can be obtained with hex(id(my_variable))), and the content of the variable. Print variables. It should look something like this (but all on one line).
{'dishes': {'type': <class 'list'>,
'address': '0x7f64f0578780',
'content': ['shish taouk', 'pizza', 'lazagna',
'spagetti', 'stroganoff beaf']
},
'menu': {'type': <class 'dict'>,
'address': '0x7f64e86be3c0',
'content': {'Monday': 'shish taouk', 'Tuesday': 'pizza',
'Wednesday': 'burger', 'Thursday': 'spagetti',
'Friday': 'stroganoff beaf', 'Saturday': 'hot dog'}
}
}