Write a Python program to Calculate the sum of the digits in an integer


Introduction

Write a Python program to Calculate the sum of the digits in an integer. I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. num = int(input("Input a four digit numbers: "))
  2. a = num //1000
  3. a1 = (num - a*1000)//100
  4. a2 = (num - a*1000 - a1*100)//10
  5. a3 = num - a*1000 - a1*100 - a2*10
  6. print("The sum of digits in the number is", a+a1+a2+a3)
  7.  

Result

python language techstudy.org

     





Related Topics




Popular Posts