Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hygull/b88a0e3733ebbbd1cdc3f6f7fb0be4af to your computer and use it in GitHub Desktop.
Save hygull/b88a0e3733ebbbd1cdc3f6f7fb0be4af to your computer and use it in GitHub Desktop.
To print sum of primes available in the entered numbers created by hygull - https://repl.it/Eo5f/2
"""
{
"date_of_creation" : "13 decemeber 2016",
"aim_of_script" : "To print sum of primes available in the entered numbers",
"my_code_on_geeksforgeeks" :"http://www.practice.geeksforgeeks.org/problem-page.php?pid=1266"
"coded_by" : "Rishikesh Agrawani",
}
"""
def is_prime(n):
if n == 1:
return False
for i in range(2,n):
if n%i == 0:
return False
return True
def get_list_of_primes(*int_nums):
primes_list = list()
for num in int_nums:
while num!=0:
rem = num%10
if is_prime(rem):
primes_list.append(rem)
num = num/10
return primes_list
def get_sum_of_list_nums(l):
s=0
for num in l:
s+=num
return s
test_cases = int(raw_input())
sums_list = []
for t in range(test_cases):
n=int(raw_input())
l=get_list_of_primes(n)
sums_list.append(get_sum_of_list_nums(l))
for s in sums_list:
print s
""" Expected output as expected in geeksforgeeks...
3
333
686
123
587
173
9
0
5
12
10
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment