i made a code to split an integer and add them individually but in some scenario the sum is wrong for example the output expected for 555 is 15 but it shows 16
def find_sum_of_digits(number):
sum_of_digits=0
sum=0
var=0
#Write your logic here
while number>0:
var = number%10
sum += var
number = number/10
sum_of_digits=sum
return int(sum_of_digits)
#Provide different values for number and test your program
sum_of_digits=find_sum_of_digits(123)
print("Sum of digits:",sum_of_digits)
The output i want is to add 123 to display 6 and as vice versa to other integer values
Aucun commentaire:
Enregistrer un commentaire