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 3 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 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()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!