The following code will print the prime numbers between 1 and 100. Modify the code so it prints every other prime number from 1 to 100


In [ ]:
for num in range(1,101): # for-loop through the numbers
    prime = True # boolean flag to check the number for being prime
    for i in range(2,num): # for-loop to check for "primeness" by checking for divisors other than 1
        if (num%i==0): # logical test for the number having a divisor other than 1 and itself
            prime = False # if there's a divisor, the boolean value gets flipped to False
    if prime: # if prime is still True after going through all numbers from 1 - 100, then it gets printed
        print(num)

Extra Credit: Can you write a procedure that runs faster than the one above?


In [ ]:
prime_list = []
prime_odd_list =[]
for num in range(1,101): 
    prime = True 
    for i in range(2,num): 
        if (num%i==0): 
            prime = False 
    if prime:         
        prime_list.append(num)
        
        #counter to print the elements at the odd positions
count = 1
for i in prime_list:
    if (count % 2) != 0: #if the position isn't at an even location
        prime_odd_list.append(i)
    count = count+1
print(prime_odd_list)