programming-examples/python/_Basics/Calculate the sum of the digits in an integer.py

6 lines
230 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
num = int(input("Input a four digit numbers: "))
x = num //1000
x1 = (num - x*1000)//100
x2 = (num - x*1000 - x1*100)//10
x3 = num - x*1000 - x1*100 - x2*10
print("The sum of digits in the number is", x+x1+x2+x3)