Question: Please only write this program in Python. I dont use any other languages. Finally, complete the lunchBi11) function. This function takes a single list argument
Finally, complete the lunchBi11) function. This function takes a single list argument whose first element is a numerical value (the base price of my lunch order) and whose remaining elements (if any) are 2-element sublists that modify the base price as described below A sublist whose first element is the string "ip" means to add a tip of the given percentage (the second element) to the total so far. For example, the sublist l-tip-, 25) means "apply a 25% tip. by multiplying the current bill amount by 1.25 (thus increasing it by 25%). To get the tp mullplier, add mp amount/100) 1o 1.0. A sublist whose first element is the string "extra" means to add the specified amount (the second element) to the total so tar. For example, the sublist t"extra, 51 means "add 5 to the current bill amount A sublist whose first element is the string "coupon" means to subtract the specified amount (the second element) from the total so tar. For example, I"coupon, 31 means "subtract 3 trom the current bill amount A sublist whose first element is the string "discount means to subtract the specified percentage (the second element) from the total so far For example, rdiscount", 35] means to apply a 35% discount by muliplying the current bill amount by 0.85 (to get the discount multiplier, subtract (discount amount/ 100) from 1) The functon argument may contain any number of tip, extra, coupon, and discount sublists, in any order. These modifiers MUST be applied in the same order that they appear in the main list. For each modifier, print a brief summary of the adjustment (e.g-Adding a 20% tip") The function should return the final bill amount or the final amount is less than 0 (meaning that my lurch was tree) tony Brook University SE 101: Introduction to Computers (Section 01) Fall 2017 General Solution Approach Your function should begin by examining the first element of he list (the base price). Use a for loop to examine any remaining elements of the list, from index 1 through the end. For each element, use an if-elif-else chain to process the four types of bill modifiers, You may assume that any sublists that you encounter will always begin with one of the four types described above (all lowercase), and will always feature non-negative values to add, subtract, or multiply by. Finaly, at the end of the loop, use an if-else statement to determine what value to return. Example 1: The list 12-34, 'tip 15. discount.25 extra", 1.511 means that we start with a base price of $12.34. We then multiply by 1.15 to add the 15 percent tip giving us $14.191 (dont worry about rounding for this problem). Next, we apply a 25 percent discount by multiplying by 0.75 to get $10.84325 Finally, we add an extra charge of 1.5 to the bill, for a final total of $12.14325 Example 2: The list 10, tip", 20]. I"discount,20. coupon.2],"coupon,21. "coupon", 1]. Idiscount.501. coupon,2.5511 means that we start with a base price of $10. We then multply by 1.20 to add a 20 percent ip, getting $12. Next, we multply by 0.80 to apply a 20 percent discount, getting $9.. We apply three coupons in turn, subtracting $2. $2. and then $1, to get $46. Applying another 50 percent doount gives us $23. Finally, we subtract $2.55 for one final coupon, giving us a final value of-$0.25. This value is less than 0, so the function will return 0 (and they say there's no such thing as a ftree lunch!)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
