An ecommerce company plans to given their customer special discount .sum of all prime digits of total bill
def is_prime(n):
Flag=1
if n <=1:
Flag=0
else:
for i in range(2, n):
if n % i == 0:
Flag=0
if(n==2): Flag=0
return(Flag)
BillAmount = 12345
s = str(BillAmount)
Flag=0
k=0
Discount=0
for r in range(0,len(s)):
t = int(s[r])
Flag=is_prime(t)
if(Flag==1):
Discount=Discount+t
print("Total Discount = ",Discount,"%")
Comments
Leave a comment