Answer to Question #248512 in Python for Hii

Question #248512

An ecommerce company plans to given their customer special discount .sum of all prime digits of total bill


1
Expert's answer
2021-10-08T23:51:40-0400
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,"%")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS