You will be given a number and you will need to return it as a string in Expanded Form. For example:
expanded_form(12) # Should return '10 + 2'
expanded_form(42) # Should return '40 + 2'
expanded_form(70304) # Should return '70000 + 300 + 4'
NOTE: All numbers will be whole numbers greater than 0.
def expanded_form(num):
ans=""
print(num)
num=str(num)
leng=len(num)
print(leng)
for i in range(len(num)):
print (num[i])
if num[i] !="0":
ans+= str(int(num[i])*(10**(leng-i-1)))
ans+= " + "
print(ans)
ans=ans[:-3]
return ans'알고리즘 문제 > CodeWar' 카테고리의 다른 글
| Consecutive Strings (0) | 2022.09.22 |
|---|---|
| Thee Supermarket Queue (0) | 2022.09.22 |
| Vowel Count (1) | 2022.09.21 |
| Find the odd int (0) | 2022.09.21 |
| Persistent Bugger (0) | 2022.09.21 |