0% found this document useful (0 votes)
2 views1 page

Number Digit Operations Guide

The document contains Python code snippets for various operations on digits of a number. It includes calculating the sum and product of digits, reversing the number, counting the digits, and finding the largest and smallest digit. Each operation prompts the user to input a number and displays the result accordingly.

Uploaded by

vithyathar14
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Number Digit Operations Guide

The document contains Python code snippets for various operations on digits of a number. It includes calculating the sum and product of digits, reversing the number, counting the digits, and finding the largest and smallest digit. Each operation prompts the user to input a number and displays the result accordingly.

Uploaded by

vithyathar14
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

11.

Sum of Digits

Calculate the sum of all digits in a number.

num = input('Enter a number: ')

sum_digits = sum(int(d) for d in num)

print('Sum of digits:', sum_digits)

12. Product of Digits

Calculate the product of all digits in a number.

num = input('Enter a number: ')

product = 1

for d in num:

product *= int(d)

print('Product of digits:', product)

13. Reverse a Number

Reverse the digits of a number using string slicing.

num = input('Enter a number: ')

print('Reversed:', num[::-1])

14. Count Digits

Count the number of digits in a number.

num = input('Enter a number: ')

print('Number of digits:', len(num))

15. Largest and Smallest Digit

Find the largest and smallest digit in a number.

num = [int(d) for d in input('Enter a number: ')]

print('Largest:', max(num))

print('Smallest:', min(num))

You might also like