ColoradoKing ColoradoKing - 1 year ago 187
Python Question

Create asterisk box given rows and columns in main [python]

I'm changing the question as it was poorly worded with no code.
Here is the question.
I ask the user to input the rows and columns in the main function. I then send the input into another function that creates a box of asterisks with given rows and columns, then returns it to be used later on in the main.
This is what I have.

def main():
rows = int(input("Enter rows :: "))
columns = int(input("Enter cols :: "))
myBox = makeBox(rows,columns)

def makeBox(r,c):
for i in range(r):


Answer Source

Do you mean something like this

rows = 4
columns = 7

for i in range(rows):

This will output


I can't answer why to do it this way. I could explain each row of code though.

[EDIT] How to return the asterix box from a function (there are better ways but this works)

rows = 4
columns = 7

def get_table(r,c):
    table = ""
    for i in range(rows):
        table += '*'*columns+'\n'
    return table


The get_table function returns a string that contains the entire table. Notice the '\n', this indicates the character for a new line.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download