# Write Number in Expanded Form

You will be given a number and you will need to return it as a string in [Expanded Form](https://www.mathplacementreview.com/arithmetic/whole-numbers.php#expanded-form). For example:

```python
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.

If you liked this kata, check out [part 2](https://www.codewars.com/kata/write-number-in-expanded-form-part-2)!!

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Mathematics

Starter code: def expanded_form(num):
	

Solutions:
def expanded_form(num):
	num = list(str(num))
	return ' + '.join((x + '0' * (len(num) - y - 1) for (y, x) in enumerate(num) if x != '0'))


def expanded_form(n):
	result = []
	for a in range(len(str(n)) - 1, -1, -1):
		current = 10 ** a
		(quo, n) = divmod(n, current)
		if quo:
			result.append(str(quo * current))
	return ' + '.join(result)


def expanded_form(num):
	num = str(num)
	st = ''
	for (j, i) in enumerate(num):
		if i != '0':
			st += ' + {}{}'.format(i, len(num[j + 1:]) * '0')
	return st.strip(' +')


def expanded_form(num):
	return ' + '.join([str(int(d) * 10 ** p) for (p, d) in enumerate(str(num)[::-1]) if d != '0'][::-1])


def expanded_form(num):
	return ' + '.join([x.ljust(i + 1, '0') for (i, x) in enumerate(str(num)[::-1]) if x != '0'][::-1])


def expanded_form(num):
	s = str(num)
	n = len(s)
	return ' + '.join([s[-i] + '0' * (i - 1) for i in range(n, 0, -1) if s[-i] != '0'])


from math import floor, log

def expanded_form(num):
	x = 10 ** floor(log(num) / log(10))
	a = num // x
	b = num % x
	s = str(a * x)
	if b != 0:
		s += ' + ' + expanded_form(b)
	return s


def expanded_form(n):
	return (lambda s: ' + '.join((s[x] + len(s[x + 1:]) * '0' for x in range(len(s)) if s[x] != '0')))(str(n))


def expanded_form(num):
	(str_num, str_list, index_track) = (str(num), [], 0)
	for digit in str_num:
		if digit != str(0):
			val = int(digit) * 10 ** (len(str_num) - (index_track + 1))
			str_list.append(str(val))
		index_track += 1
	return ' + '.join(str_list)