Question: Exercise 2 (Based on an exercise by Cay Horstmann and Rance Necaise) A supermarket awards coupons depending on how much a customer spends on groceries.


Exercise 2 (Based on an exercise by Cay Horstmann and Rance Necaise) A supermarket awards coupons depending on how much a customer spends on groceries. For example, if you spend $50, you'll get a coupon worth 8% of that amount ($4). The following table shows the percentage used to calculate the coupon awarded for different amounts spent: Amount Spent Coupon Percentage Less than $10 No coupon Between $10 to $60 8% More than $60 to $150 10% More than $150 to $210 12% More than $210 14% Step 1: Create a new editor window and save it. Use lab5ex2.py as the file name. Step 2: Use the function design recipe (examples, header, description, body, test) to develop a function named coupon. The function has one parameter, which is the amount spent on groceries. It returns the value of the coupon. Hint: you don't need to use the Boolean operators (and, or and not). Your function definition must have type annotations and a complete docstring. Use the Python shell to test your function. After you've finished testing, close the editor window for lab5ex2.py. Exercise 3 (Based on an exercise by Cay Horstmann and Rance Necaise) A non-governmental organization needs to calculate the amount of financial assistance it will provide to needy families. The formula is as follows: If the annual household income is at least $30,000 but below $40,000 and the household has at least three children, the amount is $1,500 per child. If the annual household income is at least $20,000 but below $30,000 and the household has at least two children, the amount is $1,000 per child. If the annual household income is below $20,000, the amount is $2,000 per child. Step 1: Create a new editor window and save it. Use lab5ex3.py as the file name. Step 2: Use the function design recipe (examples, header, description, body, test) to develop a function named assistance. The function has two parameters. The first parameter is the household income. The second parameter is the number of children in the household. It returns the amount of assistance the family should receive. Hint: a function that uses Boolean operators (and, or and not) will be much shorter than one that does not. Your function definition must have type annotations and a complete docstring. Use the Python shell to test your function. After you've finished testing, close the editor window for lab5ex3.py
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
