Answer:
Here is the Python program:
import math #import math to use mathematical functions
height = float(input("Enter wall height (feet): ")) #prompts user to enter wall height and store it in float type variable height
width = float(input("Enter wall width (feet): ")) #prompts user to enter wall width and store it in float type variable width
area = height *width #computes wall area
print('Wall area: {} square feet'.format(round(area))) #displays wall area using round method that returns a floating-point number rounded
sqftPerGallon = 350 #sets sqftPerGallon to 350
paintNeeded = area/ sqftPerGallon #computes needed paint
print("Paint needed: {:.2f} gallons".format(paintNeeded)) #displays computed paint needed up to 2 decimal places
cansNeeded = int(math.ceil(paintNeeded)) #computes needed cans rounding the paintNeeded up to nearest integer using math.ceil
print("Cans needed: {} can(s)".format(cansNeeded)) #displays computed cans needed
colorCostDict = {'red': 35, 'blue': 25, 'green': 23} #creates a dictionary of colors with colors as key and cost as values
color = input("Choose a color to paint the wall: ") #prompts user to enter a color
if color in colorCostDict: #if the chosen color is present in the dictionary
colorCost = colorCostDict.get(color) #then get the color cost from dictionary and stores it into colorCost using get method that returns the value(cost) of the item with the specified key(color)
cost = cansNeeded * colorCost #computes the cost of purchasing paint of specified color per cansNeeded
print("Cost of purchasing {} paint: ${}".format(color,colorCostDict[color])) #displays the real cost of the chosen color paint
print("Cost of purchasing {} paint per {} gallon can(s): ${}".format(color,cansNeeded, cost)) #displays the cost of chosen color paint per cans needed.
Explanation:
The program first prompts the user to enter height and width. Lets say user enter 20 as height and 50 as width so the program becomes:
Wall area computed as:
area = height *width
area = 20 * 50
area = 1000
Hence the output of this part is:
Wall area: 1000 square feet
Next program computes paint needed as:
paintNeeded = area/ sqftPerGallon
Since sqftPerGallon = 350 and area= 1000
paintNeeded = 1000 / 350
paintNeeded = 2.86
Hence the output of this part is:
Paint needed: 2.86 gallons
Next program computes cans needed as:
cansNeeded = int(math.ceil(paintNeeded))
This rounds the computed value of paintNeeded i.e. 2.86 up to nearest integer using math.ceil so,
cansNeeded = 3
Hence the output of this part is:
Cans needed: 3 can(s) Next program prompts user to choose a color to paint the wall
Lets say user chooses 'blue'
So the program get the cost corresponding to blue color and multiplies this cost to cans needed to compute the cost of purchasing blue paint per gallon cans. So
cost = cansNeeded * colorCost
cost = 3 * 25
cost = 75
So the output of this part is:
Cost of purchasing blue paint per 3 gallon can(s): $75 The screenshot of the program along with its output is attached.