Search code examples
pythonpython-3.xrectangles

How do I make a rectangle with user input?


I need to make a square with 2 pieces of user input: n and m. The rectangle has to be n * m and made out of "*". I can make the square if I say for example n = (5) and m = (7), when I add make m and n user input it prints n instead of a rectangle made of "*"... This is what I have so far, what am I doing wrong?

n = int(input(3))
m = int(input(4))
for i in range(n):
    print ('*' * m)

The expected output is:

****
****
****

Edit: Ok, I think my problem is that I don't know how to correctly enter input, can anyone help me on that? Second Edit: Alright, thanks everybody for helping! I found out how it works, I didn't enter actual input after running the program. Thanks again!


Solution

  • This creates a rectangle.

    n = int(input("First number "))
    m = int(input("Second number "))
    star = "*"
    for i in range(n):
        print(star*m)
    

    Example:

    First number 4
    Second number 8
    ********
    ********
    ********
    ********