Python Forum
Magic square! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Magic square! (/thread-14786.html)



Magic square! - frequency - Dec-17-2018

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


RE: Magic square! - micseydel - Dec-17-2018

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.