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.

4
  • draw shapes using graphics or ascii shapes ? Commented Mar 28, 2017 at 2:05
  • 1
    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. Commented Mar 28, 2017 at 5:45
  • Try learning to use Matplotlib or other similar tools to draw a line segment. Then it is quite easy to draw any shape by sequentially drawing line segments. Commented Mar 30, 2017 at 9:03
  • Turtle works well for me. Try this: youtu.be/aKLsCOLEmVw Commented May 16, 2024 at 7:41

1 Answer 1

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.