0

This is the code i have written :

print("Enter the number row and columns")
row, column = input().split()
print("Enter the rectangle size")
m, n = input().split()
Squares=row(row+1)(2*row+1)/6
print("Squares="+Squares)

Problem : Inputs are :

  • row and column : 3 and 3
  • m and n : 2 and 2

index values to be found out in a 3*3 matrix

The problem is from m and n how many squares of 2*2 matrix can be made in a 3*3 matrix

expected output: Squares=4

Can anyone help ?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Kaverappa KU
  • 87
  • 1
  • 7
  • What do you expect `row(row+1)(2*row+1)/6` to mean? `row` isn't the name of a function, you can't put `(row+1)` after it. – Barmar Jul 25 '18 at 08:40
  • `row(row+1)(2*row+1)/6` are you trying to multiply `row` with `(row+1)` and `(2*row+1)` with `row(row+1)` ? This is a mathematical notation but you have to be explicit and do `row*(row+1)*(2*row+1)/6` – T.Nel Jul 25 '18 at 08:42
  • 1
    You also seem to convert string to int before algebraic operations: https://stackoverflow.com/q/642154/4636715 – vahdet Jul 25 '18 at 08:42
  • Why doesn't your formula use `column`, `m` and `n`? – Barmar Jul 25 '18 at 08:43
  • Maybe you should change the question's title to fit the question for future references. It's unclear if you are dealing with square or rectangles since you have two input for each size, if you want to deal with squares only m and n are identical and can be reduce to one variable, same for row and column. Also the answer to this question is `print(4)`. The title could be improved by change 2*2 to m*n and 3*3 to variables too. – T.Nel Jul 25 '18 at 08:52

1 Answers1

2

The answer is quite simply (row - m + 1) * (column - n + 1).

So change:

Squares=row(row+1)(2*row+1)/6

to:

Squares = (row - m + 1) * (column - n + 1)
T.Nel
  • 1,540
  • 2
  • 18
  • 34
blhsing
  • 91,368
  • 6
  • 71
  • 106
  • And what if i want to know in how many 2*2 matrix the index (1,1) is included. For that answer will be 1 because (1,1) is included in only one 2*2 grid – Kaverappa KU Jul 25 '18 at 10:15