Advertisement
BbJLeB

06. Sum Prime Non Prime

Jun 4th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. # 06. Sum Prime Non Prime
  2.  
  3. sum_prime = 0
  4. sum_not_prime = 0
  5.  
  6. while True:
  7.     command = input()
  8.     if command == "stop":
  9.         break
  10.     num = int(command)
  11.     if num < 0:
  12.         print("Number is negative.")
  13.         continue
  14.     if num == 0 or num == 1:
  15.         sum_not_prime += num
  16.         continue
  17.     if num > 1:
  18.         for i in range(2, num):
  19.             if (num % i) == 0:
  20.                 is_prime = False
  21.                 break
  22.         else:
  23.             is_prime = True
  24.     else:
  25.         is_prime = False
  26.     if is_prime:
  27.         sum_prime += num
  28.     else:
  29.         sum_not_prime += num
  30.  
  31. print(f"Sum of all prime numbers is: {sum_prime}")
  32. print(f"Sum of all non prime numbers is: {sum_not_prime}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement