'New to python, Do I need a while loop statement [duplicate]

I'm new to python and I am trying to figure out how do I enter an error message if the user inputs a number less than zero. Here is my code to give you a better understanding and I thank you all in advance for any advice.

# Python Program printing a square in star patterns. 

length = int(input("Enter the side of the square  : "))

for k in range(length):
    for s in range(length):
        if(k == 0 or k == length - 1 or s == 0 or s == length - 1):
            print('*', end = ' ')
        else:
            print('*', end = ' ')
    print()


Solution 1:[1]

You can use this code after the input statement and before for loop.

       if length < 0 :
       Print("invalid length")
       Break

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rahul Khatikmare