# Average table area per person

```from math import pi # width (in), length (in), fits people tables_rect = [ [36,36,2], [48,38,4], [60,38,6], [72,38,6], [84,38,8], ] # diameter (in), fits people tables_circle = [ [36,2], [48,4], [54,4], [72,8] ] # small_d (in), large_d (in), fits people tables_ellipse = [ [60,48,6] ] table_types = ['rect', 'circle', 'ellipse'] all_tables = [tables_rect, tables_circle, tables_ellipse] def rect_area(width, length): return width * length def circle_area(diam): return pi * (diam/2)**2 def ellipse_area(large_diam, small_diam): return pi * (large_diam * small_diam) / 4 res = {} for i, (table_type, units) in enumerate(zip(table_types, all_tables)): for unit in units: if table_type == 'rect': width, length, fits_people = unit res['%s: %s" x %s", %s people' % (table_type, width, length, fits_people)] = rect_area(width, length) / fits_people elif table_type == 'circle': diam, fits_people = unit res['%s: %s", %s people' % (table_type, diam, fits_people)] = circle_area(diam) / fits_people else: # ellipse large_diam, small_diam, fits_people = unit res['%s: %s" x %s", %s people' % (table_type, large_diam, small_diam, fits_people)] = ellipse_area(large_diam, small_diam) / fits_people print('Average table area per person (in2):\n') s = sorted(res.items(), key=lambda x: x[1])[::-1] for k, v in s: print("%.2f %s" % (v, k)) print('\nSource: "Home decor cheat sheets" book') ``` ```Average table area per person (in2): 648.00 rect: 36" x 36", 2 people 572.56 circle: 54", 4 people 508.94 circle: 72", 8 people 508.94 circle: 36", 2 people 456.00 rect: 72" x 38", 6 people 456.00 rect: 48" x 38", 4 people 452.39 circle: 48", 4 people 399.00 rect: 84" x 38", 8 people 380.00 rect: 60" x 38", 6 people 376.99 ellipse: 60" x 48", 6 people Source: "Home decor cheat sheets" book```