Sum of 4 digit in python

Sum of 4 digit in python

x=eval(input(" Enter The value: "))
y=x//1000
y1=(x-y*1000)//100
y2=(x-y*1000-y1*100)//10
y3=x-y*1000-y1*100-y2*10
print("Sum of the entered no. is: ",y+y1+y2+y3)

Output

Enter The value: 1234
Sum of the entered no. is: 10

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.