How would you code for the following functions in python (function prototypes are below), to receive a list of tuples th
Posted: Fri Apr 29, 2022 7:01 am
How would you code for the following functions in python
(function prototypes are below), to receive a list of tuples that
contains menu items and prices and will return a formatted string
output of the menu item and price (required output is in the second
image). I can't use a for loop or the in function, please show
using a while loop.
- Menu Items and Prices: [("Krusty Burger",
5.10), ("Milkshake", 3.50), ("Krusty meal set [Burger + Drink +
Krusty laugh]", 10.50)]
- Function Prototypes:
- Desired Output:
def get_order (menu: list) -> list: Prompts user for order quantity for each menu item in the list. Input - a list of tuples. Returns - a list of integers Example: If order for apple is 1 and orange is 2. >>> sample = [('apple', 1.50), ('orange', 2.90)] >>> check = get_order (sample) Enter order for apple: Enter order for orange: >>> print(check) [1, 2] pass def get_summary(combined: list, gst_rate:int = 5) -> tuple: Produces the order summary formatted according to given specification. Output includes the calculated sub-total, gst and total bill. Input: list of tuples - menu item and order quantity. int- gst rate. Output: tuple of string object and float values. + Example: >>> sample = [('apple', 1.50), ('orange', 2.90)] >>> orders = [1, 2] >>> sample_orders = list(zip(sample, orders)) >>> print (sample_orders) [(('apple', 1.5), 1), (('orange', 2.9), 2)] >>> print(get_summary (sample_orders)[0]) apple orange Sub-total GST Total >>> print (get_summary(sample_orders) [1]) (7.3, 0.37, 7.67) $ $ $ 1.50 X 1 2.90 x 2 7.30 $ 0.37 $ 7.67 pass
def get_summary_bill(item: str, total: float) -> str: Display amount in tabular form. Input - item name and its total. Returns - formatted string output. Example: >>>print(get_summary_bill('Sub-total', 1.5-2)) Sub-total $ 3.00 pass def get_subtotal(price: float, quantity: int) -> float: Calculate sub-total bill given price and quantity. Input - price of item and order quantity of item. Returns - sub-total of order. Example: >>>print(get_subtotal(1.5, 2)) 3.0 pass def get_gst(total: float, rate: int) -> float: Calculate goods and services tax levied on bill. Input - Amount which tax is to be applied and tax rate. Returns - goods and services tax amount. Example: >>> print (get_gst(3.0, 5)) 0.15 pass
Enter order for Krusty Burger: #1 Enter order for Milkshake: 0 Enter order for Krusty Meal Set [Burger + Drink • Krusty Laugh]: AC Order Summary Krusty Burger Milkshake Krusty Meal Set(Burger + Drink + Krusty Laugh) Sub-total GST Total $ 5.10 x 1 $ 3.50 x 0 $ 10.50 x 0 $ 5.10 $ 0.26 $ 5.36
(function prototypes are below), to receive a list of tuples that
contains menu items and prices and will return a formatted string
output of the menu item and price (required output is in the second
image). I can't use a for loop or the in function, please show
using a while loop.
- Menu Items and Prices: [("Krusty Burger",
5.10), ("Milkshake", 3.50), ("Krusty meal set [Burger + Drink +
Krusty laugh]", 10.50)]
- Function Prototypes:
- Desired Output:
def get_order (menu: list) -> list: Prompts user for order quantity for each menu item in the list. Input - a list of tuples. Returns - a list of integers Example: If order for apple is 1 and orange is 2. >>> sample = [('apple', 1.50), ('orange', 2.90)] >>> check = get_order (sample) Enter order for apple: Enter order for orange: >>> print(check) [1, 2] pass def get_summary(combined: list, gst_rate:int = 5) -> tuple: Produces the order summary formatted according to given specification. Output includes the calculated sub-total, gst and total bill. Input: list of tuples - menu item and order quantity. int- gst rate. Output: tuple of string object and float values. + Example: >>> sample = [('apple', 1.50), ('orange', 2.90)] >>> orders = [1, 2] >>> sample_orders = list(zip(sample, orders)) >>> print (sample_orders) [(('apple', 1.5), 1), (('orange', 2.9), 2)] >>> print(get_summary (sample_orders)[0]) apple orange Sub-total GST Total >>> print (get_summary(sample_orders) [1]) (7.3, 0.37, 7.67) $ $ $ 1.50 X 1 2.90 x 2 7.30 $ 0.37 $ 7.67 pass
def get_summary_bill(item: str, total: float) -> str: Display amount in tabular form. Input - item name and its total. Returns - formatted string output. Example: >>>print(get_summary_bill('Sub-total', 1.5-2)) Sub-total $ 3.00 pass def get_subtotal(price: float, quantity: int) -> float: Calculate sub-total bill given price and quantity. Input - price of item and order quantity of item. Returns - sub-total of order. Example: >>>print(get_subtotal(1.5, 2)) 3.0 pass def get_gst(total: float, rate: int) -> float: Calculate goods and services tax levied on bill. Input - Amount which tax is to be applied and tax rate. Returns - goods and services tax amount. Example: >>> print (get_gst(3.0, 5)) 0.15 pass
Enter order for Krusty Burger: #1 Enter order for Milkshake: 0 Enter order for Krusty Meal Set [Burger + Drink • Krusty Laugh]: AC Order Summary Krusty Burger Milkshake Krusty Meal Set(Burger + Drink + Krusty Laugh) Sub-total GST Total $ 5.10 x 1 $ 3.50 x 0 $ 10.50 x 0 $ 5.10 $ 0.26 $ 5.36