-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime Num
More file actions
28 lines (23 loc) · 749 Bytes
/
Prime Num
File metadata and controls
28 lines (23 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#Method to check num is prime or not and sum the prime nums
def prime_sum():
#getting the input from user in list
nums = [int(x) for x in input('Enter a list of nums: ').split()]
#Variable for define the sum
sum = 0
for num in nums:
if num > 1:
#iterate starting from 2 to n value
for i in range(2, num):
#condition to check prime num
if num % i == 0:
print(num,'is not prime')
break
#prime num and its sum
else:
print(num,'Prime')
sum = sum + num
#print result
else:
print(num,'is not prime')
print('Sum of the Prime Num',sum)
prime_sum()