Answered step by step
Verified Expert Solution
Link Copied!

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 calculate_paint_needed(length, width, height, doors, windows):
total_wall_area =2*(length + width)* height
total_door_area = sum(door["length"]* door["width"] for door in doors)
total_window_area = sum(window["length"]* window["width"] for window in windows)
total_wall_area -= total_door_area + total_window_area
gallons_needed = total_wall_area /100.0
return gallons_needed
def get_valid_input(prompt, validation_func):
while True:
try:
value = input(prompt)
value = float(value)
if validation_func(value):
return value
else:
print("Invalid input. Please try again.")
except ValueError:
print("Invalid input. Please enter a valid number.")
def validate_positive(value):
return value >0
def main():
length = get_valid_input("Enter the length of the room in feet: ", validate_positive)
width = get_valid_input("Enter the width of the room in feet: ", validate_positive)
height = get_valid_input("Enter the height of the room in feet: ", validate_positive)
total_wall_area =2*(length + width)* height
print("Total wall area before subtracting doors and windows:", total_wall_area)
print("Excellent, let's get your windows and doors in now.")
num_doors = int(get_valid_input("Enter the number of doors (must be greater than 0): ", validate_positive))
doors =[{"length": get_valid_input(f"Enter the length of door {i+1} in feet: ", validate_positive),
"width": get_valid_input(f"Enter the width of door {i+1} in feet: ", validate_positive)}
for i in range(num_doors)]
num_windows = int(get_valid_input("Enter the number of windows: ", validate_positive))
windows =[{"length": get_valid_input(f"Enter the length of window {i+1} in feet: ", validate_positive),
"width": get_valid_input(f"Enter the width of window {i+1} in feet: ", validate_positive)}
for i in range(num_windows)]
gallons_needed = calculate_paint_needed(length, width, height, doors, windows)
print(f"You will need to buy {math.ceil(gallons_needed)} gallons of paint.")
print("You will need exactly", gallons_needed, "gallons of paint for the walls after subtracting the doors and windows.")
if __name__=="__main__":
main()
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions