Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

a. Did you express your anger verbally? Physically?

Answered: 1 week ago

Question

b. Did you suppress any of your anger? Explain.

Answered: 1 week ago