title: Matrix python coding using def
body: <p>Question:</p>
  
  <p>Write a function that displays an n-by-n matrix using the following header:</p>
  
  <pre><code>def printMatrix(n):
  </code></pre>
  
  <p>Each element is <code>0</code> or <code>1</code>, which is generated randomly.</p>
  
  <p>Write a test program that  prompts the user to enter <code>n</code> and displays an n-by-n matrix. Here is a sample run: </p>
  
  <pre><code>n = 3
   010
   000
   111
  </code></pre>
  
  <p>I don't understand or even start the code. Can someone help me?</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>from random import randint
  
  def printMatrix(n):
      for i in range(n):
          for j in range(n):
              print(randint(0, 1), end="")
          print("")
  number = input("Choose your number: ")
  printMatrix(int(number))
  </code></pre>