Quinn Mulligan
Quinn Mulligan

Reputation: 13

I don't know how to make this shape in python using "#'s" and "*'s"

I'm trying to create a simple python code that will create fairly simple shapes using "#'s" and "*'s" and I'm quite new to python and would like to only use for loops and the range() function. My code may be more complicated than it needs to be, but anyway, Heres my code so far:

Shapes = int(input("please enter the number size of the shape you want"))
sShapes = input("Would you like a square, triangle, Triangle 2 or Pyramid?")
s = 0
ss = Shapes + 1

##This is the code to make a square##
if sShapes == "Square":
    for i in range(0, Shapes):
        print('*'*Shapes)

##This is the code to make a triangle##
elif sShapes == "Triangle":
    for b in range(0, ss, 1):
        print('*'*(s+1)*b)

##This is the code that does not work##
elif sShapes == "T2":
    for c in range(ss,0,-1):
        print('#'*(s+1)*c, '*')

The code that does not work is supposed to look like this:

####*
###**
##***
#****
*****

Upvotes: 1

Views: 152

Answers (2)

Yaoshicn
Yaoshicn

Reputation: 144

You may use a single variable to control the loop:

line_shape_number = 5 # Total number of shapes
for step in range(1, line_shape_number + 1):
    print '{}{}'.format('#' * (line_shape_number - step), '*' * step)

Upvotes: 0

bhansa
bhansa

Reputation: 7504

Well, here is my approach to print the above pattern

n = 6
for i in range(1, n):
    print("{}{}".format("#"*(n-i-1),"*"*i))

####*
###**
##***
#****
*****

You can pass n instead of absolute number

Upvotes: 1

Related Questions