Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Automated Area Updater | Visualization and Automation in Architectural Workflows
Python for Architects

bookChallenge: Automated Area Updater

Automating the process of updating room areas based on new dimensions can save you significant time in architectural projects. Suppose you have a list of rooms, each with a name, length, width, and area. When you receive updated measurements for some rooms, you want a function that produces a new list reflecting the recalculated areas, without altering the original data. This approach ensures accuracy in your documentation and streamlines revision workflows.

123456789101112131415161718192021222324252627282930313233343536373839
# Hardcoded list of rooms with their current dimensions and area rooms = [ {"name": "Living Room", "length": 6.0, "width": 4.0, "area": 24.0}, {"name": "Kitchen", "length": 3.5, "width": 2.5, "area": 8.75}, {"name": "Bedroom", "length": 4.5, "width": 3.0, "area": 13.5}, {"name": "Bathroom", "length": 2.0, "width": 1.8, "area": 3.6}, ] def update_room_areas(rooms, updated_dimensions): """ Returns a new list of rooms with updated dimensions and recalculated area. - rooms: list of dicts, each with 'name', 'length', 'width', 'area' - updated_dimensions: dict mapping room names to new (length, width) """ updated_rooms = [] for room in rooms: name = room["name"] if name in updated_dimensions: length, width = updated_dimensions[name] area = length * width updated_room = { "name": name, "length": length, "width": width, "area": area } else: updated_room = room.copy() updated_rooms.append(updated_room) return updated_rooms # Example usage: new_dims = { "Living Room": (6.2, 4.1), "Bathroom": (2.2, 2.0) } updated = update_room_areas(rooms, new_dims) for room in updated: print(room)
copy

This function checks each room in your list. If updated dimensions are provided for that room, it recalculates the area and constructs a new dictionary; otherwise, it copies the original data. This ensures that only the rooms with changes are affected, and no information is lost for others. With this workflow, you can efficiently handle design revisions and keep your area calculations accurate.

Tâche

Swipe to start coding

Write a function update_room_areas that:

  • Accepts two arguments: a list of room dictionaries (each with "name", "length", "width", "area") and a dictionary mapping room names to new (length, width) tuples.
  • Returns a new list of room dictionaries, updating the dimensions and recalculating the area for any room found in the update dictionary.
  • Leaves rooms not listed in the update dictionary unchanged.

Test your function with this input:

rooms = [
    {"name": "Studio", "length": 5.0, "width": 4.0, "area": 20.0},
    {"name": "Hallway", "length": 6.0, "width": 1.5, "area": 9.0},
    {"name": "Office", "length": 3.0, "width": 3.5, "area": 10.5},
]
updates = {
    "Studio": (5.2, 4.1),
    "Office": (3.2, 3.7)
}

Your returned list should reflect the updated dimensions and areas for "Studio" and "Office", while "Hallway" remains unchanged.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 3
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookChallenge: Automated Area Updater

Glissez pour afficher le menu

Automating the process of updating room areas based on new dimensions can save you significant time in architectural projects. Suppose you have a list of rooms, each with a name, length, width, and area. When you receive updated measurements for some rooms, you want a function that produces a new list reflecting the recalculated areas, without altering the original data. This approach ensures accuracy in your documentation and streamlines revision workflows.

123456789101112131415161718192021222324252627282930313233343536373839
# Hardcoded list of rooms with their current dimensions and area rooms = [ {"name": "Living Room", "length": 6.0, "width": 4.0, "area": 24.0}, {"name": "Kitchen", "length": 3.5, "width": 2.5, "area": 8.75}, {"name": "Bedroom", "length": 4.5, "width": 3.0, "area": 13.5}, {"name": "Bathroom", "length": 2.0, "width": 1.8, "area": 3.6}, ] def update_room_areas(rooms, updated_dimensions): """ Returns a new list of rooms with updated dimensions and recalculated area. - rooms: list of dicts, each with 'name', 'length', 'width', 'area' - updated_dimensions: dict mapping room names to new (length, width) """ updated_rooms = [] for room in rooms: name = room["name"] if name in updated_dimensions: length, width = updated_dimensions[name] area = length * width updated_room = { "name": name, "length": length, "width": width, "area": area } else: updated_room = room.copy() updated_rooms.append(updated_room) return updated_rooms # Example usage: new_dims = { "Living Room": (6.2, 4.1), "Bathroom": (2.2, 2.0) } updated = update_room_areas(rooms, new_dims) for room in updated: print(room)
copy

This function checks each room in your list. If updated dimensions are provided for that room, it recalculates the area and constructs a new dictionary; otherwise, it copies the original data. This ensures that only the rooms with changes are affected, and no information is lost for others. With this workflow, you can efficiently handle design revisions and keep your area calculations accurate.

Tâche

Swipe to start coding

Write a function update_room_areas that:

  • Accepts two arguments: a list of room dictionaries (each with "name", "length", "width", "area") and a dictionary mapping room names to new (length, width) tuples.
  • Returns a new list of room dictionaries, updating the dimensions and recalculating the area for any room found in the update dictionary.
  • Leaves rooms not listed in the update dictionary unchanged.

Test your function with this input:

rooms = [
    {"name": "Studio", "length": 5.0, "width": 4.0, "area": 20.0},
    {"name": "Hallway", "length": 6.0, "width": 1.5, "area": 9.0},
    {"name": "Office", "length": 3.0, "width": 3.5, "area": 10.5},
]
updates = {
    "Studio": (5.2, 4.1),
    "Office": (3.2, 3.7)
}

Your returned list should reflect the updated dimensions and areas for "Studio" and "Office", while "Hallway" remains unchanged.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 3
single

single

some-alt