Your program should do the following:

1. Prompt the user for a file name. If you get an answer that begins with 'q' or 'Q.' go to step 7.

2. Read the file that contains four lines with 4 integers each. Each integer is a positive 1- or 2-digit number.

3. Using a function that you must write, print the 16 numbers in a square as shown below.

4. Determine if the numbers form a magic square. In a magic square each row, column and the two diagonals each add up to the same sum (always 34) and each value from 1 to 16 is used exactly once in the square. Each of the tests as noted in the next step should be written as a function that prints necessary messages and returns a True if all of its tests pass and False otherwise. Your main function should print "It is a magic square" only if all of the tests pass. Each function should be appropriately named and be passed the entire square as its only parameter.

5. Print whether or not it is a magic square. If it is not, print all of the reasons found:

a. Bad row sum = __
b. Bad column sum = __
c. Bad diagonal sum = __
d. Not every integer used exactly once.

6. Loop back to step 1 and do this for another square.

7. Print "Done."

Which file? sql.txt
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1

It is a magic square. Which file? sq2.txt
16 3 2 13
9 6 7 12
4 15 14' 1
5 10 11 8

Bad diagonal sum = 44
Bad diagonal sum = 40
Which file? sq3.txt
15 3 2 13
9 6 7 12
4 15 14 1
5 10 11 8

Bad row sum = 33
Bad column sum = 33 Bad diagonal sum = 43 Bad diagonal sum = 40
Not every integer used exactly once.
Which file? q Done.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.