Python Challenges: Compute s the sum of the digits of the number 220
Write a Python program to compute s the sum of the digits of the number 220.
210 = 1024 and the sum of its digits is 1 + 0 + 2 + 4 = 7
Sample Solution:
Python Code:
def digits_sum():
n = 2**20
ans = sum(int(c) for c in str(n))
return str(ans)
print(digits_sum())
Sample Output:
31
Flowchart:
Python Code Editor:
Contribute your code and comments through Disqus.
Next: Write a Python program to find the maximum total from top to bottom of the triangle below.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics