python - Reiterate a for loop? -


I want my loop to start from the beginning instead of starting from the place where it was left Was there.

  primes = [2] cur = 3 count = 1 count & lt; 10: For the prime number: If CUR% number == 0: CUR + = 2 primes.append (CUR) print CUR CUR + = 2 count = 1 print prime number   

I could not understand what was wrong for a while and I was getting 27 as Prime Minister. Putting it into PythonTutor I came to know that it was marked as the Prime Minister because it was investigated To repeat after 27 to see if it was divisible by 3. To see There are some ways to repeat from the beginning, or should I try to find something more realistic? Thanks

You can fix this by adding while loop and To properly control the flow, break and else :

  primes = [2] cur = 3 count = 1 count & lt; 10: While this is true: For the prime number of: and for the loop 'CUR + = 2 breaks # restart: #' while 'loop breaking the prime number # For the loop without restarting the holiday' Reach the end of the CUR% number == 0 if. Append (CR) BR + = 2 count = 1   

However, it is very strange! You can simplify the following:

  primes = [2] cur = 3 while len (primes) & lt; 10: If all (CUR% number for the prime number of prime): primes.append (CUR) CUR + = 2   

Note that is all Sluggish ", so it's just incorrect as soon as cur% num == 0 .

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -