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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -