Python Forum

Full Version: Magic square!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello! I was asked to make a magic square solver program.By breaking the program into categories,i must get the user input which will be given with entries separated with commas.So far so good. But i must create lists according to the user input length. For example, if the user inputs 1,2,3,4, this is a 2X2 table, or if it is 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16it should be a 4X4 table.I am thinking to use the modulo operator to make the identification. If we have a 4x4 table i must have 4 lists or if its a 2x2 table it will be 2 lists .Any ideas would be great
I don't see how modulo is going to help you. If you get to assume that the input is valid (no gaps or anything) you can just take the square root of the length of the number of comma-separated numbers.