fork download
  1. def is_prime(n):
  2. """Checks if a number is prime."""
  3. if n <= 1:
  4. return False
  5. for i in range(2, int(n**0.5) + 1):
  6. if n % i == 0:
  7. return False
  8. return True
  9.  
  10. sum_of_primes = 0
  11. primes = []
  12. for i in range(2, 1000):
  13. if is_prime(i):
  14. sum_of_primes += i
  15. primes.append(i)
  16.  
  17. print(f"The sum of prime numbers under 1000 is: {sum_of_primes}")
  18. print(f"The 10th prime number under 1000 is: {primes[9]}")
Success #stdin #stdout 0.04s 9700KB
stdin
Standard input is empty
stdout
The sum of prime numbers under 1000 is: 76127
The 10th prime number under 1000 is: 29