Ad

Print a square of numbers, but in a string rather then a list.

Improvement ideas, add a second parameter to choose whether the output should be a list or string.

Code
Diff
  • def square(n,s=0):
        l=["*"*n]*n
        return '\n'.join(l) if s else l
    • def square(n):
    • print(("*" *n+"\n")*n) # to see the result
    • return (("*" *n+"\n")*n)[:-1]
    • def square(n,s=0):
    • l=["*"*n]*n
    • return '\n'.join(l) if s else l