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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -