Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:35:33+00:00 2026-06-14T03:35:33+00:00

I need to check if the number the user insert is already in the

  • 0

I need to check if the number the user insert is already in the colum, row or “block” (still working on the last part).
for some reason these checks don’t work and I don’t get why?
I wrote the same code in the shell and it worked just fine.

my code:

def is_valid_move(board,row, column, digit):
    if digit in board[row]:
        print "Row already contains", digit
        return (False)
    else:
        return (True)

    for i in range(9):
        if digit in board[i][row]:
            print "Colum already contains", digit
            return (False)
            break
        else:
            return (True)

board = [[3,7,0,0,5,0,0,0,0],
         [0,6,0,0,3,0,2,0,0],
         [0,2,9,4,0,0,0,7,8],
         [0,0,4,1,7,0,0,8,0],
         [0,0,6,3,0,5,9,0,0],
         [0,5,0,0,8,4,1,0,0],
         [7,1,0,0,0,8,5,6,0],
         [0,0,5,0,1,0,0,2,0],
         [0,0,0,0,9,0,0,1,3]]

a=is_valid_move(board,1, 2, 9)
print a

output I get:

True

any idea how to check if number is already in the box?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:35:34+00:00Added an answer on June 14, 2026 at 3:35 am

    The problem is that you return true, as soon as you find any check that does not fail. So if you have a valid row, your check is already successful, although the column could be full with the same number.

    So basically, remove all return True lines and put a single one at the very end after all checks are over.

    Also a few more things:

    • Don’t put parentheses around True or False in your returns.
    • You don’t need to break after return as the latter will already end the function.
    • board[i][row] evaluates in a single digit, so a check with digit in will not work as it expects an iterable.
    • board[i][row] should be board[i][column] as the first list index is already the row.

    To check if the third condition for a 3×3 group is valid, you first need to identify which “box” a cell belongs to, and then check all the numbers inside:

    # get the first row/column index of a block
    blockRow = row // 3 * 3
    blockColumn = column // 3 * 3
    
    # check all 8 fields in the block
    for r in range(blockRow, blockRow + 3):
        for c in range(blockColumn, blockColumn + 3):
            # skip the field we want to check
            if r == row and c == column:
                continue
    
            if digit == board[r][c]:
                return False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to check in PHP if user entered a decimal number (US way,
I need to lower my received sequence number for performing FIX certification to check
I need to check some settings for all users on Windows clients in the
I need to check if some pictures (eps, tiff files) are in 300 DPI
I'm looking for a good way to check a number that a user has
I need to check if the user is logged in or not in CodeIgniter.
I need to create a completely random number for each user on my website
I need to check if the user entered a integer in a scanf() (in
testGroupList is a list of integer. I need to check the numbers in testGroupList
I need to check for a condition on each page I visit on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.