Answered step by step
Verified Expert Solution
Link Copied!

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 user-defined functions that calculate cost and discount at checkout. Perform the following steps:
a. Create a function named calculate_total that takes two arguments: number of items and price per item. This function should return the total cost
b. Create another function named calculate_discount that takes two arguments: total cost and discount rate. This function should return the discount amount.
c. 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.
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 0, your program should catch this error and ask for the input again.
h. Call the calculate_final function with the user-provided 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions