Write a Python script that accepts two matrices as input and performs matrix multiplication, ensuring that the dimensions are compatible for multiplication. If they are not compatible, print an error message.
PLAINFORMAT
def input_matrix():
    matrix = []
    print("Enter the number of rows and columns (space-separated):")
    rows, cols = map(int, input().split())
    print(f"Enter {rows} lines with {cols} space-separated elements:")
    for _ in range(rows):
        row = list(map(float, input().split()))
        if len(row) != cols:
            raise ValueError("Invalid number of elements in a row.")
        matrix.append(row)
    return matrix

def multiply_matrices(a, b):
    result = [[0] * len(b[0]) for _ in range(len(a))]
    for i in range(len(a)):
        for j in range(len(b[0])):
            for k in range(len(b)):
                result[i][j] += a[i][k] * b[k][j]
    return result

def main():
    print("Matrix A:")
    matrix_a = input_matrix()
    print("Matrix B:")
    matrix_b = input_matrix()

    if len(matrix_a[0]) != len(matrix_b):
        print("Error: Incompatible dimensions for matrix multiplication.")
    else:
        product = multiply_matrices(matrix_a, matrix_b)
        print("Product of matrices A and B:")
        for row in product:
            print(*row)

if __name__ == "__main__":
    main()