Answer to Question #312618 in Python for Mohammed

Question #312618

An e-commerce company plans to give their customers a special discount for the Christmas They are planning to offer a flat discount. The discount value is calculated as the sum of all the prime digits in the total bill amount.






Write an algorithm to find the discount value for the given total bill amount.

1
Expert's answer
2022-03-16T10:23:30-0400
def calc_discount(bill):
    discount = 0
    while bill > 0:
        d = bill % 10
        bill //= 10
        if is_prime_digit(d):
            discount += d
    return discount


def is_prime_digit(d):
    return d in [2, 3, 5, 7]



def main():
    bill = int(input('Enter a bill amount: '))
    discount = calc_discount(bill)
    print('Your discount is', discount)


main()

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