Question: Python tuples, dictionaries, and sparse matrix storage and implementation _________________________________________________________________________________________ def fruit_dictionary(): 1. Interactive dictionary: In the previous exercise, we used a fruit dictionary,

Python tuples, dictionaries, and sparse matrix storage and implementation _________________________________________________________________________________________ def fruit_dictionary(): """  1. Interactive dictionary:  In the previous exercise, we used a fruit dictionary, but if the fruit the user queries does not exist in the  dictionary, we just say "we don't have ****".  Now let's improve the design of this code: if the user queries a know fruit, we output the description.  Otherwise, we ask the user "tell me what is ****", take the user's input and add the fruit into the dictionary.  This program should run repeatedly until the users queries "quit" as a fruit name.   Below is a sample input/output:   type a name of fruit (or "quit"):apple  good for making cider  type a name of fruit (or "quit"):peach  tell me what is peachyou can find it in the quarters of Georgia state  type a name of fruit (or "quit"):lime  a sour, green citrus fruit  type a name of fruit (or "quit"):peach  you can find it in the quarters of Georgia state  type a name of fruit (or "quit"):quit  """  fruit = {"orange": "a sweet, organge, citrus fruit", "apple": "good for making cider", "lemon": "a sour, yellow citrus fruit", "grape": "a small, sweet fruit growing in bunches", "lime": "a sour, green citrus fruit"} def sparse_matrix(x, y): """  2. store and validate a sparse matrix implemented with dictionary:  In this function, we create a matrix with x rows and y columns.  The program asks the user to add more item by specifying the x index, y index and value repeatedly.  If the user types an x-index or y-index out of range, the program should not add it into the dictionary.  At the beginning of each round of the loop, you should output the matrix.  Use can type "quit" to quit the program.   You can assume that all the values in the matrix are integers   Sample input/output:  0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  add one more item (x, y, value, or 'quit'):1,1,2 0 0 0 0 0  0 2 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  add one more item (x, y, value, or 'quit'):2,2,4 0 0 0 0 0  0 2 0 0 0  0 0 4 0 0  0 0 0 0 0  0 0 0 0 0  add one more item (x, y, value, or 'quit'):10,10,100 invalid input  """  matrix ={} # ------------------------------- # Test 1 fruit_dictionary() print("--"*20) # Test 2 sparse_matrix(5, 5) print("--"*20) 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!