The task is very simple.

You must to return pyramids. Given a number ```n```  you print a pyramid with ```n``` floors

For example , given a ```n=4``` you must to print this pyramid:

```
   /\
  /  \
 /    \
/______\ 
   
```

Other example, given a ```n=6``` you must to print this pyramid:

```  
     /\
    /  \
   /    \
  /      \
 /        \
/__________\

```

Another example, given a ```n=10```, you must to print this pyramid:

```
         /\
        /  \
       /    \
      /      \
     /        \
    /          \
   /            \
  /              \
 /                \
/__________________\

```

Note: an extra line feed character is needed at the end of the string. Case `n=0` should so return `"\n"`.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Ad-hoc

Starter code: def pyramid(n):
	

Solutions:
def pyramid(n):
	return '\n'.join(('/{}\\'.format(' _'[r == n - 1] * r * 2).center(2 * n).rstrip() for r in range(n))) + '\n'


def pyramid(n):
	return '\n'.join((('/%s\\' % (' _'[i == n - 1] * i * 2)).rjust(n + i + 1) for i in range(n))) + '\n'


def pyramid(n):
	return ''.join((f"{' ' * (n - i - 1)}/{(' ' if i < n - 1 else '_') * i * 2}\\\n" for i in range(n)))


def pyramid(n):
	result = ''
	for i in range(n - 1):
		result += ' ' * (n - i - 1) + '/' + ' ' * i * 2 + '\\\n'
	result += '/' + '_' * 2 * (n - 1) + '\\\n'
	print(result)
	return result


def pyramid(n):
	result = ''
	for x in range(n, 0, -1):
		result += '{}/{}\\\n'.format(' ' * (x - 1), ('_' if x == 1 else ' ') * ((n - x) * 2))
	return result


pyramid = lambda n: ''.join(('{}/{}\\\n'.format(' ' * (n - i - 1), '_ '[i < n - 1] * i * 2) for i in range(n)))


def pyramid(n):
	output = [' ' * (n - i - 1) + '/' + ' ' * (i * 2) + '\\\n' for i in range(n)]
	output[-1] = output[-1].replace(' ', '_')
	return ''.join(output)


def pyramid(n):
	if n == 0:
		return '\n'
	s = ''
	t = 0
	while n > 1:
		s += ' ' * (n - 1) + '/' + ' ' * t + '\\\n'
		n -= 1
		t += 2
	s += '/' + '_' * t + '\\\n'
	return s