# Write Number in Expanded Form - Part 2

This is version 2 of my ['Write Number in Exanded Form' Kata](https://www.codewars.com/kata/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/decimals.php#writing-a-decimal-in-expanded-form). For example:

```python
expanded_form(1.24) # Should return '1 + 2/10 + 4/100'
expanded_form(7.304) # Should return '7 + 3/10 + 4/1000'
expanded_form(0.04) # Should return '4/100'
```

Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code:
def expanded_form(num):
	

Solutions:
def expanded_form(num):
	(integer_part, fractional_part) = str(num).split('.')
	result = [str(int(num) * 10 ** i) for (i, num) in enumerate(integer_part[::-1]) if num != '0'][::-1]
	result += [str(num) + '/' + str(10 ** (i + 1)) for (i, num) in enumerate(fractional_part) if num != '0']
	return ' + '.join(result)


def expanded_form(num):
	xs = str(num).split('.')
	return ' + '.join([f"{x}{'0' * i}" for (i, x) in enumerate(xs[0][::-1]) if x != '0'][::-1] + [f'{x}/{10 ** i}' for (i, x) in enumerate(xs[1], 1) if x != '0'])


def expanded_form(num):
	parts = str(num).split('.')
	return ' + '.join([str(int(p) * 10 ** (len(parts[0]) - i - 1)) for (i, p) in enumerate(parts[0]) if p != '0'] + ['{}/{}'.format(d, 10 ** i) for (i, d) in enumerate(parts[1], 1) if d != '0'])


def expanded_form(num):
	integer = [n + '0' * i for (i, n) in enumerate(list(str(num).split('.')[0])[::-1]) if n != '0']
	decimal = [n + '/1' + '0' * (i + 1) for (i, n) in enumerate(list(str(num).split('.')[1])) if n != '0']
	return ' + '.join(integer[::-1] + decimal)


def expanded_form(num):
	(first_part, second_part) = str(num).split('.')
	first_length = len(first_part)
	result = [elem + '0' * (first_length - i - 1) for (i, elem) in enumerate(first_part) if elem != '0']
	result += [elem + '/1' + '0' * (i + 1) for (i, elem) in enumerate(second_part) if elem != '0']
	return ' + '.join(result)


def expanded_form(num):
	(num_1, num_2) = map(str, str(num).split('.'))
	count = 0
	ls = []
	length = len(num_1)
	for i in num_1:
		length -= 1
		x = i + '0' * length
		if x != '0':
			ls.append(x)
	for i in num_2:
		count += 1
		x = i + '/' + '1' + '0' * count
		if x.split('/')[0] != '0':
			ls.append(x)
	return ' + '.join(ls)


def expanded_form(n):
	(integer, decimal) = str(n).split('.')
	l = len(integer)
	integer = [f"{digit}{'0' * (l - i)}" for (i, digit) in enumerate(integer, 1) if digit != '0']
	decimal = [f"{digit}/1{'0' * i}" for (i, digit) in enumerate(decimal, 1) if digit != '0']
	return ' + '.join(integer + decimal)


def expanded_form1(num):
	a = len(str(num))
	b = []
	for (i, j) in enumerate(str(num)):
		if j != '0':
			b.append(j + '0' * (a - i - 1))
	return ' + '.join(b)

def expanded_form(num):
	a = str(num).index('.')
	m = int(str(num)[:a])
	n = '0' + str(num)[a + 1:]
	b = []
	for (i, j) in enumerate(n[1:]):
		if j != '0':
			b.append(j + '/1' + '0' * (i + 1))
	b = ' + '.join(b)
	if len(expanded_form1(m)) > 0:
		return expanded_form1(m) + ' + ' + b
	else:
		return b


def expanded_form(num):
	split = str(num).split('.')
	tens = [str(int(x) * 10 ** i) for (i, x) in enumerate(split[0][::-1]) if x != '0'][::-1]
	decimals = [f'{x}/{10 ** i}' for (i, x) in enumerate(split[1], 1) if x != '0'] if '.' in str(num) else []
	return ' + '.join(tens + decimals)


def expanded_form(num):
	num = str(num)
	index = num.index('.')
	leng = len(num) - index - 1
	num = num[:index] + num[index + 1:]
	ans1 = ' + '.join((num[i] + (index - i - 1) * '0' for i in range(index) if num[i] != '0'))
	ans2 = ' + '.join((num[i + index] + '/1' + (i + 1) * '0' for i in range(leng) if num[i + index] != '0'))
	return ans2 if not ans1 else ans1 + ' + ' + ans2