Digit Sum in Python with user input -
i have code:
def digit_sum(n): total = 0 while true: = n % 10 n = n // 10 total = total + if n < 1 : break return total print digit_sum(12584521)
in code above want allow user input number. example, user inputs 12584521, hits enter , result appears (in example result 28). how modify code above that?
thanks
try this
print digit_sum(input("enter num: "))
for python2.x , 3.x
print(digit_sum(int(input("enter num: "))))
Comments
Post a Comment