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 8468417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:55:34+00:00 2026-06-10T15:55:34+00:00

First of all, here’s the code: def check_sudoku(n): d=len(n) i=0 s=1 while i<d: print

  • 0

First of all, here’s the code:

def check_sudoku(n):
    d=len(n)
    i=0
    s=1
    while i<d:
        print "i=",i
        while s<d:
            print "s=",s
            if n[0][i]==n[s][i]:
                return False
            s=s+1
            i=i+1
         return True 

what I want to do is that after the value of s changes from 1 to d, then it loops again and the value of i changes.
But in my code the value of i is not changing at all.

Just to be clear of what I want to do,
say

n =[[1,2,3,4],
    [2,3,1,3],
    [3,1,2,3],
    [4,4,4,4]]

i want the following to happen:

  • first it should check for

    n[0][0]==n[1][0]
    n[0][0]==n[2][0]
    n[0][0]==n[3][0]
    

    after that value of i should increase by 1

  • then it should go like this:

    n[0][1]==n[1][1]
    n[0][1]==n[2][1]
    n[0][1]==n[3][1]
    

after this value of i will increase again and this same loop will run.

This is not happening and I am not sure why.
Please tell me what changes I should make to make it run the way I want to.

  • 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-10T15:55:36+00:00Added an answer on June 10, 2026 at 3:55 pm

    Your inner loop increments s until it is greater than d, but you never set it back to 1. Also, with your current indentation, you also increment i in the inner loop, so it’ll reach d inside the inner loop causing the outer loop to only be run once too.

    So, if d is 4, your values will go:

    i = 0, s = 1
    i = 1, s = 2
    i = 2, s = 3
    # exit inner loop
    return True
    

    You’d be much better off using for loops using range(), avoiding your mistakes altogether:

    def check_sudoku(n):
        for i in range(len(n)):
            for s in range(1, len(n)):
                if n[0][i]==n[s][i]:
                    return False
        return True
    

    With range the inner loop will always start at 1, range through to len(n) every time without explicit resets needed.

    If you use the any() function you can collapse the whole test into one line:

    def check_sudoku(n):
        return not any(n[0][i] == n[s][i] for i in range(len(n)) for s in range(1, len(n)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all here is my code so that you can test it to
First than all sorry that I can put code here, the best way is
First of all i'm new in here and new with csharp. just exhausted while
First of all here are some code snippets: public void startThread() { this.animationThread =
First of all, here's my code: var users = {}; //User Connect io.sockets.on('connection', function
first at all, here is my code: string pdfTemplate = Application.StartupPath + \\Templates\\Template Medico.pdf;
First of all, here is my code snippet: var str = '<!--:de-->some german text<!--:--><!--:en-->some
first of all, i have to tell you that i have searched here and
first of all here is my code: @protocol SearchTableViewControllerDelegate @required - (void)didSelectFileCardsContent:(FileCardsContent*)content; @end @interface
first of all, I want to assure that I'm aware of the fact, that

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.