Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Python program that contains multiple user - defined functions that calculate cost and discount at checkout. Perform the following steps: a . Create
Write a Python program that contains multiple userdefined functions that calculate cost and discount at checkout. Perform the following steps:
a Create a function named calculatetotal that takes two arguments: number of items and price per item. This function should return the total cost
b Create another function named calculatediscount that takes two arguments: total cost and discount rate. This function should return the discount amount.
c Create a third function named calculatefinal 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 $ after a discount of $ has been applied to the total of $Z replacing and with the calculated values.
g 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 your program should catch this error and ask for the input again.
h Call the calculatefinal function with the userprovided values and print the returned string.
i Provide comments in your code to explain the logic used.
j Test your program with different inputs and ensure that it performs the calculations correctly.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started