How to Sum of Digits in Python

Given a Number to find sum of Digit in Python


input = 356
Output = 14

Below the method to Sum of Digit Only Allow for Three digit

three_digit = input(“Type a Three Digit Number: “)

first_digit = three_digit[0]
second_digit = three_digit[1]
third_digit = three_digit[2]

result = int(first_digit) + int(second_digit) + int(third_digit) print(result)


Method – 2 Using for loop function for infinite Digit :

test = input(“Type How Many Digit for sum: “)

sum = 0 for i in test:
sum += int(i)



Thank You ! ❤️


How to Create Mail Server on RHEL Machine

Leave a Reply

Your email address will not be published. Required fields are marked *