0

Write a program that draws one of three shapes depending on the user's choice: a square, a rectangle or triangle.

Your program will prompt the user to enter their choice of shape: 's' for square, 'r' for rectangle, and 't' for triangle. If a user enters a character that is not 's', 'r' or 't', the program should display a message indicating that the user’s choice was an incorrect type of shape.

If the user enters a valid choice, your program will prompt the user to enter the size of the shape. This will be the length of the side of the square, both the length of the "across" side and length of the "down" side for the rectangle, or the length of the side of a right triangle.

Ivan Kolesnikov
  • 1,787
  • 1
  • 29
  • 45
  • draw shapes using [graphics](https://docs.python.org/3/library/turtle.html) or [ascii shapes](http://stackoverflow.com/questions/13076194/ascii-art-in-python-updated) ? – chickity china chinese chicken Mar 28 '17 at 02:05
  • Copy-pasting the text of your school assignment is NOT the way to ask questions on SO. Please, do some research of your own and ask when you face exact problems with your solution. – Eduard Malakhov Mar 28 '17 at 05:45
  • Try learning to use [Matplotlib](http://matplotlib.org) or other similar tools to draw a `line` segment. Then it is quite easy to draw any shape by sequentially drawing line segments. – Developer Mar 30 '17 at 09:03

1 Answers1

0

From what i understood you are asking the user to input the shape and amount of rows. When this program prompts the user to input rows he should type 10 for any shapes given, however if you don't want the user to choose the amount of rows just comment out the #j=int(input("Enter rows: ")) and replace it with a global variable j=10.

s=str(input("Enter your shape(s for square, t for triangle or r for rectangle): "))
j=int(input("Enter rows: "))
shape=str(s)


if shape == 't':
    print("   I'm a pyramid")
    print()

    for x in range(0,j):
        for z in range(0,j-x-1):
            print(end=" ")
        for z in range(0,2*x+1):
            print('#',end="")
        print()

    print()
    print("   I'm a pyramid")
    print('____________________')
    print()


elif shape == 's':
    print("   I'm a square")
    print()

    for x in range (1,10):
        for z in range(20,1,-1):
            print("#", end='')
        print(' ')

    print()
    print("   I'm a square")
    print('____________________')
    print()

elif shape =='r':
    print("   I'm a rectangle")
    print()

    for x in range (1,10):
        for z in range(40,1,-1):
            print("#", end='')
        print(' ')

    print()
    print("   I'm a rectangle")
    print('____________________')
    print()

else:
    print('Only the options given mate')
Habtoor
  • 1
  • 1