Python Challenges: Compute s the sum of the digits of the number 220
Python Challenges - 1: Exercise-43 with Solution
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python-exercises/challenges/1/python-challenges-1-exercise-43.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics