Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I edit this code to input all the numbers in one input, rather than one at a time, while also disregarding any spaces

image text in transcribed

image text in transcribed

How would I edit this code to input all the numbers in one input, rather than one at a time, while also disregarding any spaces between the numbers for the input.

For example, right now I input the 9 numbers one at a time, but I would like to be able to input it all in one line for the same result, like this:

123456789 or 1 23 456 78 9

so that both of those inputs would result in the same answer

def checkMagicSquare (mat) : Purpose: This function checks if the square is magic or not. Parameters: mat - the entered matrix Returns: True #printing the entered matrix print() for i in range(3): fori in range(0,3): print(mat[i][j], end=" ") print() # calculate the the prime diagonal's sum Sum = 0 for i in range(0, 3) : Sum = Sum + mat[i][i] 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 # calculate the secondary diagonal's sum sum2 = 0 for i in range(0, 3) : sum2 = sum2 + mat[i][3-i-1] if(Sum!=sum2) : return false # Row Sums for i in range(0, 3) : rowSum = 0; for j in range(0, 3) : rowSum += mat[i][j] # check if the sum of every row is equal to the sum of each # prime diagonal if (rowSum != Sum) : return False # Column Sums for i in range(0, 3): colSum = 0 for j in range(0, 3) : colsum += mat[j][i] # check if the sum of each column is equal to the sum of each # prime diagonal if (Sum != col Sum) : return false return True print('----Magic square checker---- ') print('Please enter the numbers 1 through 9 in the order you want them in the square :') square = [] 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 for i in range(3): row = 1 for i in range(3): row.append(int(input())) square.append(row) if (checkMagicSquare(square)) : print(" The square is Magic!") else: print(" Sorry, that isn't a Magic Square")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions