w3resource

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 Flowchart: Compute s the sum of the digits of the number 2<sup>20</sup>.

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Python program to find the starting number, under ten thousand will create the longest chain.

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.



Follow us on Facebook and Twitter for latest update.