Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Help making PYTHON code more modular with function getAreaRecs ( ) which totals areas of windows and doors. Image helps. My code: import math def
Help making PYTHON code more modular with function getAreaRecs which totals areas of windows and doors. Image helps. 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
Help making PYTHON code more modular with function getAreaRecs which totals areas of windows and doors. Image helps.
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
Step: 1
Get Instant Access with AI-Powered 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