Codelab Python help Dont need print Just coding please Assum
Codelab Python help! (Don\'t need print) Just coding please.
Assume you have a variable , budget, that is associated with a positive integer. Assume you have another variable , shopping_list, that is a tuple of strings representing items to purchase in order of priority. (For example: (\"codelab\", \"textbook\", \"ipod\", \"cd\", \"bike\")) Furthermore, assume you have a variable , prices that is a dictionary that maps items (strings such as those in your shopping_list) to positive integers that are the prices of the items.
Write the necessary code to determine the number of items you can purchase, given the value associated with budget, and given that you will buy items in the order that they appear in the tuple associated with shopping_list. Associate the number of items that can be bought with the variable number_of_items.
Solution
Note: I have assumed random prices for items mentioned in question.
prices = {\"codelab\" : 50, \"textbook\" : 100, \"ipod\" : 150, \"cd\" : 200, \"bike\" : 250}
 def computeNumberOfItemsToBeShopped(budget,shoppingList):
 number_of_items = 0
 for item in shoppingList:
 if budget > 0 and prices[item] <= budget: #check if budget is left and prices of item is less than budget
 number_of_items += 1
 budget -= prices[item]
 return number_of_items
print(computeNumberOfItemsToBeShopped(150,[\"codelab\",\"textbook\"]))

