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.
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()
Comments
Leave a comment