Answer:
In Python:
def calcCost(length,width,quality):
if quality == 1:
cost = length * width * 3.50
if quality == 2:
cost = length * width * 2.50
else:
cost = length * width * 1.50
return cost
length = float(input("Room Length: "))
width = float(input("Room Width: "))
print("Quality:\n1 - Best\n2 - Moderate\n3 and others - Worst")
quality = int(input("Quality: "))
print("Calculate: "+str(calcCost(length,width,quality)))
Explanation:
This defines the function calcCost to calculate the carpeting cost
def calcCost(length,width,quality):
If quality is 1, the total cost is calculated by area * 3.50
<em> if quality == 1:</em>
<em> cost = length * width * 3.50</em>
If quality is 2, the total cost is calculated by area * 2.50
<em> if quality == 2:</em>
<em> cost = length * width * 2.50</em>
For other values of quality, the total cost is calculated by area * 1.50
<em> else:</em>
<em> cost = length * width * 1.50</em>
This returns the calculated carpeting cost
return cost
The main begins here
This prompts the user for the length of the room
length = float(input("Room Length: "))
This prompts the user for the width of the room
width = float(input("Room Width: "))
This gives instruction on how to select quality
print("Quality:\n1 - Best\n2 - Moderate\n3 and others - Worst")
This prompts the user for the quality of the carpet
quality = int(input("Quality: "))
This calls the calcCost method and also printst the calculated carpeting cost
print("Calculate: "+str(calcCost(length,width,quality)))