You get this error because you use the variable list1 in the main function but you haven't defined it. I believe that list1 that you want to use in the main function is the list which is returned in the setupRectangle function. So there is 2 ways to fix this error.
The first solution is to change rect = setupRectangle() to list1 = setupRectangle().
The second solution is to change all the variable list1 to rect. For example:
for i in range(len(rect)):
I would also recommend using better variable names. For example, in the setupRectangle function, instead of list1, it would be better to use rectList.