Sum Product Reverse of digits in Number coderinme

Sum Product Reverse of digits in Number coderinme

Sum, Product, Reverse of digits in Number
Now we shall code to calculate the sum, product and reverse of entered number.
For example: If the entered number is 123
then , sum = 1 + 2 + 3 = 6
product = 1 * 2 * 3 = 6
reverse = 321

#!/usr/bin/env python
num=int(raw_input("Enter the no.: "))
sum = 0
rev = 0
prod = 1
while (num != 0):
rem = num % 10
num = num // 10
sum += rem
rev = rev * 10 + rem
prod *= rem
print "Sum of digits of the number are: ", sum
print "Reverse of digits of the number are: %d" %rev
print "Product of digits of the number are: {:d}".format(prod)

For more programs on Python, visit our Python Coder Archives

Sum Product Reverse of digits in Number coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.