Tech Study

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.

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

Result

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

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

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more