Reference no: EM132816770
Develop a python program Write the algorithm and the Python code to implement a solution to the following problem.
A magic square is an arrangement of numbers in a square grid, where the numbers in each row, each column, and each diagonal all add up to the same number ... that number is called a magic constant. The value of the magic constant, M, associated with a square that has n rows and columns is given by the formula:
M = n * (n2 + 1) / 2
The smallest possible magic square is a 3x3 grid, i.e., the above formula is only meaningful for n >= 3. In other words:
- the 1st magic square is a 3x3 grid (n = 3; M = 15)
- the 2nd magic square is a 4x4 grid (n = 4; M = 34)
- etc.
Your program should ask the user how many magic constants to display, validate that the user has entered a positive integer, calculate the requested constants, and print the result in exactly the following format. For example, if the user enters 4, your message should say:
The first 4 magic constants are: 15, 34, 65, 111.