Created
October 4, 2020 06:13
-
-
Save graphicagenda/c2cbc666ac3423f92d94b653bcd143a8 to your computer and use it in GitHub Desktop.
Code Wars Kata: Numbers in Expanded Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.codewars.com/kata/5842df8ccbd22792a4000245/train/python | |
def expanded_form(num): | |
num = list(str(num)) | |
store = [] | |
for i in range(len(num)): | |
x = int(num[i]) | |
if x > 0: | |
store.append(str(int(x * ( 10 ** (len(num) - int(i) - 1)) ))) | |
return ' + '.join(store) | |
print(expanded_form(70304)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment