-5

I am trying to write a program that prints a parallelogram. When I compile the Python code below, I get IndentationError: expected an indented block

# the required mehtod
def repeatChar(numRepeats, outputChar):
#this function outputs the output char numRepeats times
output=""
for i in range(numRepeats):
output=output+outputChar
return output
def main():
print("This program will output a prallelogram.")
side=int(input("How long do you want wach side to be? "))
char=input("Please enter the character you want it to be made of: ")
output=""
#loop to output the top triangle
for i in range(1,side+1):
output=output+repeatChar(i, char)+"\n"
#loop to output the bottom triangle
for i in range(1,side+1):
#appnds the empty space i times and then appends the char
output=output+repeatChar(i," ")+repeatChar((side-i), char)+"\n"
print(output)
main()

Why?

A T
  • 1
  • 3
    There's no indentation at all in your code. That's what it's complaining. – Underoos Apr 05 '20 at 11:40
  • You forgot to indent your function body, and your for loop bodies, etc. Indentation is not an option in Python. It is part of the syntax of the language. You should probably read a tutorial before proceeding further. There is literally nothing more basic than this. – Tom Karzes Apr 05 '20 at 11:40
  • you do know that python uses indentation to know which part of your code are grouped, where older languages would use {}? So give indentation to code inside loops/conditional statements – Eric Apr 05 '20 at 11:40

1 Answers1

1

"Why?" - Because you did not indent anything.


# the required mehtod
def repeatChar(numRepeats, outputChar):
    # this function outputs the output char numRepeats times
    output = ""
    for i in range(numRepeats):
        output = output + outputChar
    return output


def main():
    print("This program will output a prallelogram.")

    side = int(input("How long do you want wach side to be? "))
    char = input("Please enter the character you want it to be made of: ")
    output = ""
    # loop to output the top triangle
    for i in range(1, side + 1):
        output = output + repeatChar(i, char) + "\n"
    # loop to output the bottom triangle
    for i in range(1, side + 1):
        # appnds the empty space i times and then appends the char
        output = output + repeatChar(i, " ") + repeatChar((side - i), char) + "\n"
    print(output)


main()

Works for me.

Lydia van Dyke
  • 2,466
  • 3
  • 13
  • 25