code:-
num=int(input("Enter a number"))
di_sum=0
while num!=0:
# seperate digits from number
rem=num%10
# add digits
di_sum=di_sum+rem
num=num//10 # integer division
print("Sum of digits is: ",di_sum)
Output:-
Enter a number1234
Sum of digits is: 10
2 Comments
✌️✌️
ReplyDeleteBasic series aa gayi thank you sir
ReplyDelete