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
    8226
    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 cvp

      @mibradoc this code works but I don't understand yours: why ==8 and the "*3" is not visible

      Édit: visually, all between the two "*" becomes italic

      box_altex = 8 
      for num_box in range ( (box_altex//3*3) , (box_altex//3*3)+3) :	
      	print (num_box) 
      
      1 Reply Last reply Reply Quote 0
      • cvp
        cvp @mibradoc last edited by

        @mibradoc Sure that all lines in the loop are showed here?

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

          Yes, I'am. And loop works fine diretly in shell, but fails in my script, checked with stop points

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

            @mibradoc code prints

            
            >>> 6
            >>> 7
            >>> 8
            
            

            as requested. are you wanting this to print that resault 3 times?

            
            >>> 6
            >>> 7
            >>> 8
            
            >>> 6
            >>> 7
            >>> 8
            
            >>> 6
            >>> 7
            >>> 8
            
            
            1 Reply Last reply Reply Quote 0
            • stephen
              stephen @cvp last edited by

              @cvp

              i do want to add that the original post is saying

              
              where box_altex == 8:
                  for num_box in range ( (box_altex//3*3) , (box_altex//*33)+3) :
                      print (num_box)
              

              of course that throws error so im assuming that its ( (box_altex//3*3) , (box_altex//3*3)+3)

              im guessing a few things:

              • im thinking @mibradoc is tryingbto run a while do while loop possibly since it seems likenhe wants it to run more than once?
              • the where box_altex == 8: was meant box_altex = 8 and this states the loop should run once.

              i tried many implementations and other than obvious i get the 123 type ressult. so im not sure how his code in script would alter the outcome. unless example givin differs from actuall..

              sorry @mibradoc

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

                @stephen he said where, not while...

                stephen cvp 2 Replies Last reply Reply Quote 0
                • stephen
                  stephen @JonB last edited by stephen

                  @JonB

                  yes sir i was just giving my input on "if" it was a typo. similar to his missplacement of the asterisk. this is why i used i think and ?. when helping i try to be as thorough as i can..

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

                    @JonB & @stephen I think that "where box_altex == 8" is not part of the script, only to say that this variable has the value 8. The script is between the 2 "..." lines

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

                      @mibradoc You say that the code jumps to the line after the loop. I think that we need the full code, if it is possible

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

                        here is full code :
                        https://www.dropbox.com/sh/puqht9zcmjfrzsh/AAA1_zJt1Kt0YFU3avW2dHeja?dl=0

                        stephen cvp 3 Replies Last reply Reply Quote 0
                        • stephen
                          stephen @mibradoc last edited by stephen

                          UPDATED

                          @mibradoc output:

                          
                          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
                          0
                          1
                          2
                          (3, 2) [3, 5] 0
                          0
                          1
                          2
                          (5, 4) [3, 5] 3
                          3
                          4
                          5
                          (7, 5) [0, 2] 4
                          3
                          4
                          5
                          (9, 3) [4, 5] 5
                          3
                          4
                          5
                          (3, 4) [3, 4] 3
                          3
                          4
                          5
                          (8, 0) [3, 5] 2
                          0
                          1
                          2
                          (8, 0) [3, 5] 2
                          0
                          1
                          2
                          
                          [[1 4 3 0 7 0 9 2 3]
                           [3 0 0 0 0 2 8 5 4]
                           [0 0 0 0 5 0 6 1 7]
                           [0 0 5 2 3 5 3 7 0]
                           [9 7 6 0 0 7 4 0 1]
                           [0 5 0 0 0 6 0 9 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]]
                          40
                          3
                          
                          
                          cvp 1 Reply Last reply Reply Quote 0
                          • cvp
                            cvp @mibradoc last edited by

                            @mibradoc run gives an error

                            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
                            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 @stephen last edited by

                              @stephen did you change code?

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

                                @mibradoc you say
                                "The for loop is line # 141
                                using breakpoint you 'll see the jump to line 147 after the first print "

                                but line 147 is still in the loop, due to its indentation

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

                                  @cvp yes im sorry, didnt realize it didnt paste in

                                  I CHANGED:

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

                                  not sure what expected outcome isnexpected tho

                                  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 ()
                                  
                                  
                                  cvp 1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp @stephen last edited by

                                    @stephen understood, we will wait on réaction about my last post.

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

                                      @cvp this feels more like what hes probably looking for? comented out print (numero_carre)
                                      on line 143

                                      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
                                      (3, 2) [3, 5] 0
                                      (5, 4) [3, 5] 3
                                      (7, 5) [0, 2] 4
                                      (9, 3) [4, 5] 5
                                      (3, 4) [3, 4] 3
                                      (8, 0) [3, 5] 2
                                      (8, 0) [3, 5] 2
                                      
                                      [[1 4 3 0 7 0 9 2 3]
                                       [3 0 0 0 0 2 8 5 4]
                                       [0 0 0 0 5 0 6 1 7]
                                       [0 0 5 2 3 5 3 7 0]
                                       [9 7 6 0 0 7 4 0 1]
                                       [0 5 0 0 0 6 0 9 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]]
                                      40
                                      3
                                      
                                      
                                      cvp 1 Reply Last reply Reply Quote 0
                                      • cvp
                                        cvp @stephen last edited by

                                        @stephen I don't know, up to @mibradoc to tell us more

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

                                          That 's correct, line 147 is still in the loop. But I 've commented lines 143 and 144 because the nameError and insert line 142 in order to debug. I don't need this print line in my script.
                                          If you uncomment 143 and 144 and if the loop works fine, the name error would dissapear.
                                          Wich version of Pythonista do you use? Mine is 3.3

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

                                            @mibradoc Pythonista 3.3 too
                                            You need also to uncomment 146

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