veronikaaa86

03. Sum Prime Non Prime

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