Question: Problem 4 : User - Defined Functions Points Possible: 4 0 This problem will provide you with an opportunity to demonstrate your understanding of creating

Problem 4: User-Defined Functions
Points Possible: 40
This problem will provide you with an opportunity to demonstrate your understanding of creating multiple user-defined functions where one or more functions use another functions return value as input.
Instructions:
Write a Python program that contains multiple user-defined functions that calculate cost and discount at checkout. Perform the following steps:
Create a function named calculate_total that takes two arguments: number of items and price per item. This function should return the total cost.
Create another function named calculate_discount that takes two arguments: total cost and discount rate. This function should return the discount amount.
Create a third function named calculate_final that takes four arguments: the number of items, the price per item, the minimum number of items purchased that qualifies for a discount, and the discount rate. This function should call the other two functions, passing the appropriate arguments. It should apply the discount if the number of purchased items reaches the required minimum. It should return a string that says "The final cost is $X after a discount of $Y has been applied to the total of $Z.", replacing X, Y, and Z with the calculated values.
Prompt the user to enter values for the number of items, the price per item, the minimum number of items purchased that qualifies for a discount, and the discount rate. If the user enters any negative number or 0, your program should catch this error and ask for the input again.
Call the calculate_final function with the user-provided values and print the returned string.
Provide comments in your code to explain the logic used.
Test your program with different inputs and ensure that it performs the calculations correctly.
When your program runs, it should match the expected output below exactly. Go back in and put in labels as needed.

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 Programming Questions!