Michael Wells
Michael Wells

Reputation: 37

Having trouble locating logically error, for loop with recursion

My goal is to print numbers from 1 to 9 with no repeats using the logic: for each number in the array to be printed,

Upvotes: 1

Views: 15

Answers (1)

Hammad Ahmed
Hammad Ahmed

Reputation: 885

p = np.zeros((1,9), dtype=int)

  def check_row(i):
    num = random.randint(1,9)
    # check num equal any number in its row
    for nine in range(9):
      if num == p[i][nine]:
          num = check_row(i)  
      else:
          pass    
    return num

 for j in range(9):
   if p[0][j] == 0:
     p[0][j] = check_row(0)

 print(p)

Upvotes: 1

Related Questions