如何用if在python里求一个数是否为质数

is_prime that consumes a Natural number(n) and returns True if n is prime (its only positive divisors are 1 and n), and False otherwise.

# -*- coding: UTF-8 -*-

def is_prime(n):
    if n < 2: return False
    if n == 2: return True
    for i in range(2, n / 2 + 1):
        if n % i == 0: return False
    return True

for i in range(100):
    if (is_prime(i)): print(i)

如果问题得到解决,请点下采纳,谢谢合作