Python Exercises - Sum of Digits of a Number (Daily Python Practice #13)

preview_player
Показать описание
In this video, we will create python program that add the digits of a number and print the sum of the digits. This python exercise will use type conversion where we will convert integers to string so that we can go through the digits one by one.

In this exercise we will see the concepts of variables, type conversion and loops in python.

I'll upload daily python practice problems, so subscribe to follow along and practice python daily!

Python Exercise #13: Add Digits of a Number using Python

First 15 Python Exercises from Daily Python Practice Series:
1. Take User Input and Print
2. Temperature Converter
3. Print Pyramid using *
4. Reverse a String
5. Print Even or Odd
6. Check if a number is prime
7. Palindrome Checker
8. Factorial Calculator
9. Generate Fibonacci Sequence
10. Word Counter
11. Add Two Numbers
12. Filter Even Numbers from a List
13. Sum of Digits of a given number
14. Leap Year Checker
15. Armstrong Number Checker
More Daily Exercises Coming Soon...

Practice python with these beginner python exercises every day, and be a python pro!

#pythonexercises #pythonpractice #digitsum #dailypractice
Рекомендации по теме
Комментарии
Автор

number = int(input(""))
str_no = str(number)
digit_sum = sum(int(i) for i in str_no)
digit_list = [i for i in str_no]
print(f" + ".join(map(str, digit_list))+" = "+str(digit_sum))

jowey_
welcome to shbcf.ru