Question: Python code: Help make code more modular with function getAreaRecs ( ) which totals areas of windows and doors, and writing a program that reads
Python code: Help make code more modular with function getAreaRecs which totals areas of windows
and doors, and writing a program that reads the test files created and prints them out line by line.
So I need help replacing the loops to get total area of the windows and total area of the doors with the getAreaRecs function. Also help to adding to my program to write all input and output to a file.
My code:
import math
def calculatepaintneededlength width, height, doors, windows:
totalwallarea length width height
totaldoorarea sumdoorlength doorwidth for door in doors
totalwindowarea sumwindowlength windowwidth for window in windows
totalwallarea totaldoorarea totalwindowarea
gallonsneeded totalwallarea
return gallonsneeded
def getvalidinputprompt validationfunc:
while True:
try:
value inputprompt
value floatvalue
if validationfuncvalue:
return value
else:
printInvalid input. Please try again."
except ValueError:
printInvalid input. Please enter a valid number."
def validatepositivevalue:
return value
def main:
length getvalidinputEnter the length of the room in feet: validatepositive
width getvalidinputEnter the width of the room in feet: validatepositive
height getvalidinputEnter the height of the room in feet: validatepositive
totalwallarea length width height
printTotal wall area before subtracting doors and windows:", totalwallarea
printExcellent let's get your windows and doors in now."
numdoors intgetvalidinputEnter the number of doors must be greater than : validatepositive
doors length: getvalidinputfEnter the length of door i in feet: validatepositive
"width": getvalidinputfEnter the width of door i in feet: validatepositive
for i in rangenumdoors
numwindows intgetvalidinputEnter the number of windows: validatepositive
windows length: getvalidinputfEnter the length of window i in feet: validatepositive
"width": getvalidinputfEnter the width of window i in feet: validatepositive
for i in rangenumwindows
gallonsneeded calculatepaintneededlength width, height, doors, windows
printfYou will need to buy mathceilgallonsneeded gallons of paint."
printYou will need exactly", gallonsneeded, "gallons of paint for the walls after subtracting the doors and windows."
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
