I'm learning to program in Python. Can you write an example of a Python program that compute (rejected answer)
- User
Human: I'm learning to program in Python. Can you write an example of a Python program that computes the union of three rectangles specified by the user? Please make sure it's really well commented.
- Assistant
Here is a basic implementation of the union of three user-specified rectangles, implemented in Python:
Compute the intersection of three user-defined rectangles
with width and height specified by the user
def compute_rect_union(r1_w,r1_h,r2_w,r2_h,r3_w,r3_h): # To compute the intersection rectangle, compute the minimum # and maximum corner coordinates for the three input rectangles x1 = max(r1_w, r2_w, r3_w) y1 = max(r1_h, r2_h, r3_h) x2 = min(r1_w+r1_h, r2_w+r2_h, r3_w + r3_h) y2 = min(r1_h+r1_w, r2_h+r2_w, r3_h+r3_w)
# If the minimum x value is greater than the maximum y value, # then the two resulting corners will fall outside of the range [x1, x2], # so we return an empty rectangle. Otherwise, the resulting # rectangle will be a non-empty rectangle. if x1 > y2: return {} else: return dict(x1=x1, y1=y1, x2=x2, y2=y2)Get rectangle corners from user
r1_w = float(input("r1 width: ")) r1_h = float(input("r1 height: ")) r2_w = float(input("r2 width: ")) r2_h = float(input("r2 height: ")) r3_w = float(input("r3 width: ")) r3_h = float(input("r3 height: "))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.