Answer to Question #263410 in Python for Vinee

Question #263410

an ecommerce company plans to give their customers a discount for the new year. the discount will be calculated on the basis of the bill amount is the product of the sum of all odd digits and the sum of even digits of the customer's total bill. if no odd-even digit is represented in the bill amount then 0 will be returned?

1
Expert's answer
2021-11-09T10:21:54-0500
# Function to return the
# reverse of a number
def reverse(n):
  rev = 0
  while (n != 0):
    rev = (rev * 10) + (n % 10)
    n //= 10
  return rev


# Function to find the sum of the odd
# and even positioned digits in a number
def getSum(n):


  n = reverse(n)
  sumOdd = 0
  sumEven = 0
  c = 1


  while (n != 0):


    # If c is even number then it means
    # digit extracted is at even place
    if (c % 2 == 0):
      sumEven += n % 10
    else:
      sumOdd += n % 10
    n //= 10
    c += 1


  print("Sum odd =", sumOdd)
  print("Sum even =", sumEven)


# Driver code
n = 457892
getSum(n)

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