27 lines
879 B
Python
27 lines
879 B
Python
import matplotlib.pyplot as plt
|
|
|
|
# Get the input from the user
|
|
base = float(input("Enter the length of the base of the trapezoid: "))
|
|
height = float(input("Enter the height of the trapezoid: "))
|
|
square_side = float(input("Enter the length of the side of the square: "))
|
|
|
|
# Calculate the area of the trapezoid
|
|
area = (base + height) / 2 * square_side
|
|
|
|
# Calculate the number of squares that can be divided from the trapezoid
|
|
num_squares = int(area / square_side**2)
|
|
|
|
# Create a figure and axes
|
|
fig, ax = plt.subplots()
|
|
|
|
# Draw the trapezoid
|
|
ax.fill_betweenx([height / 2, height / 2, height, height], [0, base / 2, base / 2 + base, base], color='blue')
|
|
|
|
# Draw the squares
|
|
for i in range(num_squares):
|
|
x = i * square_side
|
|
y = height / 2
|
|
ax.fill([x, x + square_side, x + square_side, x], [y, y, y + square_side, y + square_side], color='red')
|
|
|
|
# Show the plot
|
|
plt.show() |