Sum of Non-prime Digits - WIPRO
Sum of Non-prime Digits - WIPRO
Problem:
The program must accept an integer N as the input. The program must print the sum of non-prime digits in N as the output. If there is no such digit, the program must print -1 as the output.
Input 1:
219517
Output 1:
11
Input 2:
3005
Output 2:
0
Input 3:
725
Output 3:
-1
Program:
number = int(input())
total = 0
non_prime = 0
while number > 0:
rem = number % 10
if rem not in [2,3,5,7]:
total += rem
non_prime = 1
number //= 10
if non_prime:
print(total)
else:
print(-1)
Comments
Post a Comment