omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    'for loop' exit at first passage

    Pythonista
    for loop error
    4
    40
    8225
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp @mibradoc last edited by

      @mibradoc Pythonista 3.3 too
      You need also to uncomment 146

      1 Reply Last reply Reply Quote 0
      • cvp
        cvp last edited by

        This

        			for numero_carre in range ( (numcarre_altex // 3) * 3,((numcarre_altex//3)*3) + 3 ) :
        				print ('x:',numero_carre) # BUG !!  sortie de la boucle for après le 1er passage !! 
        				if numero_carre != numcarre_altex and key[0] not in carrint(numero_carre) :
        					numero_carre_sans_chiffre = numero_carre
        					
        				colonnes_possibles=[]
        				for colonne in range((numero_carre_sans_chiffre % 3)*3,(numero_carre_sans_chiffre % 3)*3 + 3) : 
        

        also crashes with

        grille à résoudre ? libre
        
        [[1 4 0 0 7 0 9 2 0]
         [3 0 0 0 0 2 8 5 4]
         [0 0 0 0 5 0 6 0 7]
         [0 0 0 2 0 0 0 7 0]
         [9 0 6 0 0 0 4 0 1]
         [0 5 0 0 0 6 0 0 0]
         [0 0 9 0 6 0 0 0 0]
         [5 3 0 7 0 0 0 0 8]
         [0 8 0 0 2 0 0 3 9]]
        50
        (1, 1) [3, 4] 2
        x: 0
        Traceback (most recent call last):
          File "/private/var/mobile/Containers/Shared/AppGroup/668A7D98-7216-47ED-917D-AA0B6173167E/Pythonista3/Documents/aa.py", line 147, in <module>
            for colonne in range((numero_carre_sans_chiffre % 3)*3,(numero_carre_sans_chiffre % 3)*3 + 3) :
        NameError: name 'numero_carre_sans_chiffre' is not defined
        
        1 Reply Last reply Reply Quote 0
        • cvp
          cvp last edited by cvp

          Your loop on colonne uses numero_carre_sans_chiffre which is only defined in a if.

          Are sure you don't need to indent more this loop?

          				if numero_carre != numcarre_altex and key[0] not in carrint(numero_carre) :
          					numero_carre_sans_chiffre = numero_carre
          					
          					colonnes_possibles=[]
          					for colonne in range((numero_carre_sans_chiffre % 3)*3,(numero_carre_sans_chiffre % 3)*3 + 3) : 
          
          1 Reply Last reply Reply Quote 0
          • mibradoc
            mibradoc last edited by

            @cvp you're right, but the bug remains on my iPad
            It's strange that the same code runs without error on your device.
            Thanks a lot to you and to @stephen

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @mibradoc last edited by

              @mibradoc As we have made some changes in your code to let it run without name error, I'm not sure we use exactly the same code.
              I also have an iPad (Mini 4) and I don't think comes from that.
              Could you post a code which runs without name error on your device but which stops after one loop

              1 Reply Last reply Reply Quote 0
              • stephen
                stephen last edited by

                pas de problème @mibradoc

                here is translated script incase anyone needed/wanted
                gist

                1 Reply Last reply Reply Quote 0
                • stephen
                  stephen last edited by

                  @cvp i beleive the error is the issue originaly. i say this only because it raises after one pass of for loop

                  cvp 1 Reply Last reply Reply Quote 1
                  • cvp
                    cvp @stephen last edited by

                    @stephen it is possible but as you have also changed some lines (comment, loop on colonne indentation), I just want to be sure that he and us try exactly the same code.

                    1 Reply Last reply Reply Quote 0
                    • mibradoc
                      mibradoc last edited by

                      The code on Dropbox stops after one loop. Whith a breakpoint on line 141 and then step by step you will see that the loop is executed only one time, not three as expected. The name error comes because the bypass over the lines 143 and 144 where the variable 'numero_carre_sans_chiffre' is assigned.

                      cvp 1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @mibradoc last edited by

                        @mibradoc yes, but as the name error occurs in the loop, it is normal the loop is stopped, isn'it?

                        1 Reply Last reply Reply Quote 0
                        • mibradoc
                          mibradoc last edited by

                          @stephen Thanks for the translation.

                          1 Reply Last reply Reply Quote 1
                          • mibradoc
                            mibradoc last edited by

                            @stephen and your code runs without errors ! Have you made some change other than translate ?

                            cvp 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @mibradoc last edited by

                              @mibradoc it was like I said, a problem of indentation of you loop on colonne!

                              1 Reply Last reply Reply Quote 0
                              • mibradoc
                                mibradoc last edited by

                                @cvp I think the errors occurs in line 147, after the loop. This cannot prevent the loop from executing three times.

                                cvp 1 Reply Last reply Reply Quote 0
                                • cvp
                                  cvp @mibradoc last edited by cvp

                                  @mibradoc the problem in your original code is that the loop on colonne was in the loop On numéro and this crashed in the first occurrence in loop.
                                  If you indent left the colonne loop, there is no crash...

                                  Your code

                                  for numéro...
                                    ...
                                    For colonne..
                                  

                                  correction

                                  for numéro...
                                    ...
                                  for colonne...
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • mibradoc
                                    mibradoc last edited by

                                    @cvp OK, I'll check indentation

                                    cvp 1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp @mibradoc last edited by

                                      @mibradoc

                                      See my previous post, edited

                                      1 Reply Last reply Reply Quote 0
                                      • mibradoc
                                        mibradoc last edited by

                                        @cvp Great, It'works. Merci les amis ;-)

                                        1 Reply Last reply Reply Quote 1
                                        • stephen
                                          stephen last edited by stephen

                                          @mibradoc

                                          I CHANGED:

                                          for colonne in range((numero_carre % 3)*3,(numero_carre % 3)*3 + 3) :
                                          #colonnes_possibles=[] ⇒ colonnes_possibles=[]

                                          
                                          
                                          for numero_carre in range ( (numcarre_altex // 3) * 3,((numcarre_altex//3)*3) + 3 ) :
                                                          print (numero_carre) # BUG !!  sortie de la boucle for après le 1er passage !! 
                                                          #if numero_carre != numcarre_altex and key[0] not in carrint(numero_carre) :
                                                              #numero_carre_sans_chiffre = numero_carre
                                                              
                                                          colonnes_possibles=[]
                                                          for colonne in range((numero_carre % 3)*3,(numero_carre % 3)*3 + 3) :
                                                                  if puzzle[ ligne_a_analyser , colonne ] == 0 and key[0] not in puzzle[:9,colonne]:
                                                                      colonnes_possibles.append(colonne)
                                                          if len(colonnes_possibles)  == 1 :
                                                              fn_remplir_case ( ligne_a_analyser , colonnes_possibles[0] , key[0] )
                                                                  #print()
                                                                  #print (puzzle)
                                                                  #print ()
                                          
                                          
                                          1 Reply Last reply Reply Quote 1
                                          • mibradoc
                                            mibradoc last edited by

                                            @stephen All is fine now, thank you.

                                            1 Reply Last reply Reply Quote 2
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors