PYTHON PROGRAM- REPEAT | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

PYTHON PROGRAM- REPEAT

Write a Python program to add the digits of a positive integer repeatedly until the result has a single digit. Input Format: The first line of the input contains a number n. Output: Print the resultant number Example: Input: 48 Output: 3 Explanation: If you add digits 4 and 8, you will get 12. Again adding 1 and 2 will give 3 which is a single digit and hence the answer.

23rd Sep 2018, 4:59 AM
Krishnanshu Dey
Krishnanshu Dey - avatar
1 Answer
- 1
Write a Python program to add the digits of a positive integer repeatedly until the result has a single digit. Input Format: The first line of the input contains a number n. Output: Print the resultant number Example: Input: 48 Output: 3 Explanation: If you add digits 4 and 8, you will get 12. Again adding 1 and 2 will give 3 which is a single digit and hence the answer.
2nd Nov 2020, 4:21 AM
Saksham Turki
Saksham Turki - avatar