1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
coldgirl [10]
3 years ago
15

There is a simple method for constructing a magic square for any odd value of n:

Computers and Technology
1 answer:
DaniilM [7]3 years ago
3 0

Answer:

See Explaination

Explanation:

class MagicSquare():

def __init__(self,side):

self.side=side

self.two_dimension=[]

for row in range(1,side+1):

row_line=[]

for col in range(1,side+1):

row_line.append(0)

self.two_dimension.append(row_line)

def display(self):

row=0

col=int((self.side-1)/2)

for i in range(1,self.side**2+1):

self.two_dimension[row][col]=i

row-=1

col+=1

if row==-1:

row=self.side-1

if col==self.side:

col=0

if self.two_dimension[row][col]==0:

continue

else:

row+=1

if row==self.side:

row==0

for line in self.two_dimension:

for num in line:

print("{0:>3}".format(num),end=" ")

print()

def main():

for i in range(1,14,2):

square=MagicSquare(i)

square.display()

print("----------------------------------------------------")

if __name__ == '__main__':

main()

You might be interested in
c g given an array, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero eleme
o-na [289]

The output for an array of elements [0,1,0,3,12] is  [1,3,12,0,0]

<h3>What is the function to get the desired output?</h3>
  • Let us consider an array of elements,

          Input = [0,1,0,3,12]

  • The function code is given by,

class Solution {

public:

   void moveZeroes(vector<int>& nums) {

       int count=0;

       for(int i=0;i<nums.size();i++)

       {

           if(nums[i]==0)

           {

               nums.erase(nums.begin()+i);

               ++count; //This is to count number of zeroes.

           }

       }

      for(int i = 0 ; i<count ; i ++)

          nums . push_back(0);  //To input zero at the end of the vector count times.      

}

};

The output for an array of elements [0,1,0,3,12] is  [1,3,12,0,0] where all 0's are moved to the end,  while maintaining the relative order of the non-zero elements,

<h3>What is an array?</h3>
  • A collection of items that are either values or variables is referred to as an array in computer science.
  • Each element is identifiable by at least one array index or key.
  • Each element of an array is recorded such that a mathematical formula can be used to determine its position from its index tuple.
  • A linear array, often known as a one-dimensional array, is the simplest sort of data structure.

To learn more about array, refer:

brainly.com/question/19634243

#SPJ4

6 0
1 year ago
Communication of a message between two processes implies which of the following? (A) Synchronization (B) Atomic operation (C) Bl
solong [7]

Answer: Synchronization

Explanation:

In communication of messages between processes we have a mechanism called as the interprocess communication (IPC) using which it is required to achieve synchronization between the process. These synchronization helps to prevent collision of the processes for the shared resources. Examples can be of mechanism of producer consumer problem .

6 0
3 years ago
Once I install my secondary hard drive what two tasks need to be done?
Vlada [557]
What is the use for the secondary hard drive?

If it is to run another operating system, such as a Linux flavour or another version of Windows, you would need to:

1) correctly format your drive

2) Install your OS

If you are using the HDD alongside your current OS, you need to:

1) Lower the boot priority of that drive in your BIOS

2) Format your hdd for use in your OS.

(Use NTFS for Windows and HFS+ for OS X)
3 0
3 years ago
What Is the Purpose of a Web Browser? *<br><br>​
Aneli [31]
A web browser takes you anywhere on the internet. It retrieves information from other parts of the web and displays it on your desktop or mobile device. The information is transferred using the Hypertext Transfer Protocol, which defines how text, images and video are transmitted on the web.
6 0
3 years ago
Read 2 more answers
What type of user account should Tuan’s brother use?
Sauron [17]

Answer:

d so if he comes back any time soon

Explanation:

6 0
3 years ago
Other questions:
  • Which term is used to describe a password-protected, encrypted data file that verifies the identity of the sender of a message?
    8·1 answer
  • Think about some of the most memorable and forgettable games ever created. They can be games that were discussed in this unit or
    10·1 answer
  • IT professionals should help to protect users’ personal information, such as bank account information or Social Security numbers
    14·1 answer
  • Can you install Ubuntu on a hard drive by porting from the folder to the HDD?
    10·1 answer
  • The intellectual property right that gives a creator control of his or her written work is known as what?
    9·1 answer
  • 4.5 code practice computer science
    5·1 answer
  • The =COUNT function calculates what value?
    15·2 answers
  • Structured query language (sql) enables data analysts to _____ the information in a database.
    7·1 answer
  • What does data warehousing allow organizations to achieve?
    12·1 answer
  • which filename refers to a 16-bit real-mode program that queries the system for device and configuration data, and then passes i
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!