I\'m supposed to write a program that ends up such as this:
* *
* *
* *
*
I have the code written for a regular one, but I\'m not s
Building on @kharazi's answer (because this reminds me of my early GWBasic programming which is what got me excited about programming as a kid):
def triangle(i, leftShape='*', rightShape='*', bottomShape='*', spaceShape=' ', t = 0):
if i <= 0:
print ((t+1)*spaceShape)+bottomShape+((t+1)*spaceShape)
else:
print (spaceShape*(t + 1))+leftShape+(spaceShape*(i*2-1))+rightShape+(spaceShape*(t + 1))
triangle(i-1, leftShape, rightShape, bottomShape, spaceShape, t+1)
if __name__== '__main__':
triangle(3)
triangle(3, '\\', '/')
triangle(3, '\\', '/', '~')
triangle(5, '╚╗', '╔╝', '╚╦╝')
triangle(5, '╚╗', '╔╝', '╚╦╝', '|')
triangle(-2)
Produces the following output:
triangle(3)
* *
* *
* *
*
triangle(3, '\\', '/')
\ /
\ /
\ /
*
triangle(3, '\\', '/', '~')
\ /
\ /
\ /
~
triangle(5, '╚╗', '╔╝', '╚╦╝')
╚╗ ╔╝
╚╗ ╔╝
╚╗ ╔╝
╚╗ ╔╝
╚╗ ╔╝
╚╦╝
triangle(5, '╚╗', '╔╝', '╚╦╝', '|')
|╚╗|||||||||╔╝|
||╚╗|||||||╔╝||
|||╚╗|||||╔╝|||
||||╚╗|||╔╝||||
|||||╚╗|╔╝|||||
||||||╚╦╝||||||
triangle(-2)
*