Advertisement
Spocoman

03. Sum Prime Non Prime

Dec 30th, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. prime = 0
  2. nonPrime = 0
  3. num = input()
  4.  
  5. while num != 'stop':
  6.     number = int(num)
  7.     if number >= 0:
  8.         if number % 2 == 0 or number % 3 == 0 or number % 5 == 0:
  9.             if number == 2 or number == 3 or number == 5 or number == 7:
  10.                 prime += number
  11.             else:
  12.                 nonPrime += number
  13.         else:
  14.             prime += number
  15.     else:
  16.         print('Number is negative.')
  17.     num = input()
  18.  
  19. print(f'Sum of all prime numbers is: {prime}')
  20. print(f'Sum of all non prime numbers is: {nonPrime}')
  21.  
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement