Sichanov

sum prime

Jul 11th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. n = input()
  2. prime_sum = 0
  3. non_prime_sum = 0
  4. not_prime = False
  5. while n != "stop":
  6.     n = int(n)
  7.     if n < 0:
  8.         print("Number is negative.")
  9.         n = input()
  10.         continue
  11.     else:
  12.         for i in range(2, n):
  13.             if n % i == 0:
  14.                 not_prime = True
  15.                 break
  16.         if not_prime:
  17.             non_prime_sum += n
  18.             not_prime = False
  19.         else:
  20.             prime_sum += n
  21.  
  22.     n = input()
  23.  
  24. print(f"Sum of all prime numbers is: {prime_sum}")
  25. print(f"Sum of all non prime numbers is: {non_prime_sum}")
Advertisement
Add Comment
Please, Sign In to add comment