Advertisement
GeorgiLukanov87

nester-exerc-no3-100/100

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