How to simplify for loop in prime number generator in python
Question: 
    import math
    
    def is_prime(num):
        if num < 2:
            return False
        for i in range(2, int(math.sqrt(num))+ 1):
            if num % i == 0:
                return False
        return True
    

Primes seems to be a popular topic but in the book in which I am learning
Python, I am on chpt 6 out of 21 and in the iteration chapter which it teaches
while loops. I have not learned for loops yet although I understand what they
do. So, let's say I have not learned for loops yet and am given only
if/elif/else statements and the while loops as my tools. How can I change the
for line of code into something more simple using the above tools? While
asking this question I quickly came up with this code:

    
    
    def formula(num):
        i = 2
        while i >= 2:
            return int(math.sqrt(num)+ 1)
    
    
    def is_primetwo(num):
        i = 2
        if num < 2:
            return False
        formula(num)
        if num % i == 0:
            return False
        return True 
    

It works but would this be a simple version of the for loop or is there
something even more simple where I do not have to wrap a function within a
function?


Answer: How about something like:

    
    
    from math import sqrt
    
    def is_prime(num):
        if (num < 2):
            return False
        i = 2
        limit = int(sqrt(num) + 1)
        while (i <= limit):
            if num % i == 0:
                return False
            i = i + 1
        return True
    

