PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Created by Zygarde
# Problem: Sum of Digits
# Write a function that takes a positive integer as input and returns the sum of its digits.
# Solve this problem **without converting the number to a STRING**.
#
# Input:
# - A single positive integer num (1 ≤ num ≤ 10⁶).
#
# Output:
# - An integer representing the sum of the digits of num.
#
# Example Runs:
#
# Example 1:
# Input: 123
# Output: 6
# (Explanation: 1 + 2 + 3 = 6)
#
# Example 2:
# Input: 9875
# Output: 29
# (Explanation: 9 + 8 + 7 + 5 = 29)
def sum_of_digits(num):
# Write your code here👍
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run