#5, First Floor, 4th Street , Dr. Subbarayan Nagar, Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to sum a given number into single digit using nested while loop in python?
Description

To sum a given number into single digit using python3.

Process

   Get the input from user.

   Initialize nested for loop.

   Use % and // operators for separating and round off the input value.

   Print the result.

Sapmle Code

#get the input from user
n=int(input(“Enter the number:”))

#declare two variable to store final result
rev=0
rev1=0

#initialize first while loop
while(n>0):
r=n%10
rev=rev+r
n=n//10
#initialize second while loop
while(rev>0):
s=rev%10
rev1=rev1+s
rev=rev//10

#print the result
print(“sum of given number is:”,rev1)

Screenshots