How To Calculate Sum of Digits Of a 3-Digit Number
#CALCULATE THE SUM OF DIGITS OF A 3-DIGIT NUMBER
print('SUM OF DIGITS OF A 3-DIGIT NUMBER')
num=a=b=c=ttl=0
num=int(input('Enter a 3-Digit Number = '))#123
if(num<100 or num>999):
print (num,'is INVALID INPUT')
else:
a=num%100
b=(num-a)/100
c=num%10#123%10=3
d=(num-(b*100)-c)/10
ttl=b+c+d
print ('The Sum Total =',ttl)
Made By :-
Nilay Saraf
Comments
Post a Comment