0

My code is here:

def pe():
  print("This program will output a parallelogram.")
 
def rows():
  row = int(input("How long do you want each side to be?"))
  return(row)
 
def de():
  character = input("Please enter the character you want it to be made of:")
 
def make_shape():
  for i in range(row):
    for j in range(1, i + 1):
        print(character, end="")
    print()
 
    for k in range(1, row + 1):
      for l in range(1, row + 1):
        if(l < k):
            print(' ', end = "")
        else:
            print(character, end = "")
    print()
 
def main():
  pe()
  rows()
  de()
  make_shape()
 
main()

Any ideas to why python is saying row is not defined? Is it not globalized or something, I'm honestly so confused.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    you return row in `rows()` but dont forward it to `make_shape()` where you want to use it. save rows to a variable `my_rows = rows()` and use is as parameter `make_shape(my_rows)`. same for `character` – luigigi Oct 01 '21 at 06:06
  • In addition to the previous comment, you also have to forward character from function de so that it will be known by function make_shape. – DarrylG Oct 01 '21 at 06:10
  • @DarrylG I tried this but now it says name 'character' is not defined – Jonathan Wong Oct 01 '21 at 06:13
  • @JonathanWong--as Tim Roberts answer illustrates you have to forward both of these parameters i.e. rows and characters to make_shape. – DarrylG Oct 01 '21 at 06:16

1 Answers1

1

It is BECAUSE they are not globalized that they aren't defined. The best way is to pass them as parameters:

def de():
  return input("Please enter the character you want it to be made of:")
...
def make_shape(row, character):
   ...
def main():
  pe()
  row = rows()
  char = de()
  make_shape(row, char)

It's a bit silly to define a function for a single line like this.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30