• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Sums of Prime/Non prime numbers JOHNYTHEWINNER  Feb 18th, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. command = ''
2. sum_prime_numbers = 0
3. sum_non_prime_numbers = 0
4. while command != 'stop':
5.     command = input()
6.     if command == 'stop':
7.         break
8.     number = int(command)
9.     if number < 0:
10.         print(f'Number is negative.')
11.     else:
12.         i = 2
13.         isprime = False
14.         for i in range(2, number):
15.             if number % i == 0:
16.                 sum_non_prime_numbers += number
17.                 isprime=True
18.                 break
19.         if (isprime==False):
20.             sum_prime_numbers += number
21. print(f'Sum of all prime numbers is: {sum_prime_numbers}')
22. print(f'Sum of all non prime numbers is: {sum_non_prime_numbers}')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top