I'm a computer science student who's just starting out with algorithms and their implementation. I wrote this code for a dynamically morphing square. I was wondering if I could get a review on it. I apologize if the comments are excessive, this is how I submitted on it at school.
import time #imported the time module to make the loop stop for a .5 sec before the next iteration
user_input = int(input("Input a number greater than 3: ")) #gets the user input in the form of an integer
def pattern(count): #created a function here called pattern, and gave it a parameter called count
while user_input > 3: #This loop works as long as the integer entered is > 3
min = 0 #initialize the variable min as the starting corner of the square i.e zero point.
max = count - 1 #initialize the variable max as "count -1". This is because this variable will be updated by the loops through each iteration.
for run in range(0,count): #first loop to control the iterations of the square
print(run) #This will print the number of the iteration we are in at the time. This is put here as a check to see if the loop works as intended.
for i in range(0,count): #this loop goes from row 0 to row N, where N is the value entered by the user.
for j in range(0,count): #this loop goes from column 0 to column N, where N is the value entered by the user. This will be responsible for printing the stars in the square, from column to column.
if (min <= max and min <= i and i <= max and min <= j and j <= max) and (i == min or i == max or j == min or j == max): #this branch checks if ceertain cinditions are met. then prints * if they are. The conditions are explained below.
print("*",end="") #prints * without a line break after every iteration of its loop
else:
print(".",end="") #prints . without a line break after every iteration of its loop
print("") #prints a new line
print("") #prints a new line
if run < count / 2: #in this branch, if the iterations of the boxes < half of the user input, the variable min will be incremented by 1
min += 1 #and the variable max will be reduced by 1
max -= 1
if run >= count / 2: #if the iterations of the boxes > half of the user input, min will be reduced by 1 and max will increase by 1.
min -= 1
max += 1
time.sleep(.5) #pauses for .5 secs between iterations of the square.
if user_input >= 3: #if the user input > 3, the function called pattern will be called
pattern(user_input)
else: #if the user input < 3, there will be an error message printed
print("Enter a number greater than 3 ")
# The first branch in this function checks if the variable min<max, if min < i <= max, if min < j <= max, if i = min, if j = min, if i = max and if j = max.
# These conditions confine the points that are printed to the space between min and max, in both the rows and columns of the square.
# The four final conditions are there to allow the square to dissappear creating a set of dots and display the first square where both rows and columns are equal to the number entered by the user.
The results are as follows: