-3

I need to make a pattern with a function, which given an integer(n) will print out a particular pattern of size n. It should look like this at size 4, for example:

!!!!!!!!!!!!!!
\\!!!!!!!!!!//
\\\\!!!!!!////
\\\\\\!!//////

Here is my code thus far. I don't know how to invert the pyramid shape, and I don't know how to get the slashes to work with the exclamation points to create the desired pattern as you can see:

def slashFigure():
    width = int(input("Enter a number: "))
    for i in range(0, width):
        for j in range(0, width - i):
            print("\\", end="")
        for k in range (0, 2*i + 1):
            print("!!", end="")
        print("/")

slashFigure()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
mothmook
  • 1
  • 2

3 Answers3

0

Try this :

def slashFigure():
    width = int(input("Enter a number: "))
    for i in range(width):
        print('\\'*(2*i)+ '!'*(width*4-i*4-2)+'/'*(2*i))

slashFigure()

Output :

Enter a number: 4
!!!!!!!!!!!!!!
\\!!!!!!!!!!//
\\\\!!!!!!////
\\\\\\!!//////
Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56
0

The following works for me

num = int(input("Enter a number: "))
length = 4 * (num - 1) + 2
exclamation = 2
lines = []
for line in range(num):
    slashes = (length - exclamation) // 2
    lines.append('\\' * slashes + '!' * exclamation + '/' * slashes)
    exclamation += 4

lines.reverse()
for print_line in lines:
    print(print_line)
LuckyZakary
  • 1,171
  • 1
  • 7
  • 19
0

You could do:

def slashFigure(height, reverse):

    for row in range(height)[::(1-int(reverse)*2)]:
        print(''.join(['\\' for x in range(row*2)]+['!' for x in range(height*4-row*4-2)]+['/' for x in range(row*2)]))

height = int(input("Enter a number: "))
slashFigure(height, False)
slashFigure(height, True)
eylion
  • 172
  • 10