Write a Python program to compute the sum of the first 100 prime numbers

Program

def main():
    sum = 1
    counter = 0
    n = 0
    while counter < 100:
        n += 1
        if n % 2 != 0:
            if is_prime(n):
                sum += n
        counter += 1
    print("\nSum of the prime numbers till 100: " + str(sum))

def is_prime(n):
    for i in range(3, int(n ** 0.5) + 1, 2):
        if n % i == 0:
            return False
    return True

if __name__ == "__main__":
    main()


Output:

Sum of the prime numbers till 100: 1060

For latest job updates join Telegram Channel: https://t.me/sateeshm

Programs