CECS 100
LAB ASSIGNMENT 10
Assigned date:
 12/2
Due date:   
12/4
40 points


Do problems 11 chapter 7 on page 404.

Partial coding:

# Global constants
ROWS = 3 # The number of rows
COLS = 3 # The number of columns
MIN = 1 # The value of the smallest number
MAX = 9 # The value of the largest number

def main():
# Create a two-dimensional list.
test_list = [ [4, 9, 2],
[3, 5, 7],
[8, 1, 6] ]

# Display the list in row and column format.
display_square_list(test_list)

# Determine if the list is a Lo Shu magic square.
if is_magic_square(test_list):
print('This is a Lo Shu magic square.')
else:
print('This is not a Lo Shu magic square.')

# The display_square_list function accepts a two-dimensional
# list as an argument, and displays the list's values in row
# and column format.
def display_square_list(value_list):
#YOUR CODE

# The is_magic_square function accepts a two-dimensional
# list as an argument, and returns True if the list meets
# all the requirements of a magic square. Otherwise it
# returns False.
def is_magic_square(value_list):
# Set status to False, initially.
status = False

# Call functions and store their return values.
is_in_range = check_range(value_list)
is_unique = check_unique(value_list)
is_equal_rows = check_row_sum(value_list)
is_equal_cols = check_col_sum(value_list)
is_equal_diag = check_diag_sum(value_list)

# Determine if the list meets all the requirements.
if is_in_range and \
is_unique and \
is_equal_rows and \
is_equal_cols and \
is_equal_diag:

# If it does, set status to True.
status = True

# Return the status.
return status

# The check_range function accepts a two-dimensional
# list as an argument, and returns True if the values
# in the list are within the specified range. Otherwise,
# it returns False.
def check_range(value_list):
# Initialize status to True.
status = True

# Step through all the values in the list.
#YOUR CODE

# The check_unique function accepts a two-dimensional
# list as an argument, and returns True if the values
# in the list are unique. Otherwise, it returns False.
def check_unique(value_list):
# Initialize status to True.
status = True
# Initialize the search value.
search_value = MIN
# Initialize the counter to zero.
count = 0

# Perform the search while the maximum value
# has not been reached, and the values are
# unique.
while search_value <= MAX and status == True:
# Step through all the values in the list.
# YOUR CODE

# Return the status.
return status

# The check_row_sum function accepts a two-dimensional
# list as an argument, and returns True if the sum of
# the values in each of the list's rows are equal.
# Otherwise, it returns False.
def check_row_sum(value_list):
# Initialize status to True.
status = True

# Calculate the sum of the values in the first row.
sum_row_0 = value_list[0][0] + \
value_list[0][1] + \
value_list[0][2]

# Calculate the sum of the values in the second row.
sum_row_1 = value_list[1][0] + \
value_list[1][1] + \
value_list[1][2]

# Calculate the sum of the values in the third row.
sum_row_2 = value_list[2][0] + \
value_list[2][1] + \
value_list[2][2]

# Determine if the sum of any of the rows is not equal.
# YOUR CODE

# Return the status.
return status

# The check_col_sum function accepts a two-dimensional
# list as an argument, and returns True if the sum of
# the values in each of the list's columns are equal.
# Otherwise, it returns False.
def check_col_sum(value_list):
# Initialize status to True.
status = True

# Calculate the sum of the values in the first column.
sum_col_0 = value_list[0][0] + \
value_list[1][0] + \
value_list[2][0]

# Calculate the sum of the values in the second column.
sum_col_1 = value_list[0][1] + \
value_list[1][1] + \
value_list[2][1]

# Calculate the sum of the values in the third column.
sum_col_2 = value_list[0][2] + \
value_list[1][2] + \
value_list[2][2]

# Determine if the sum of any of the columns
# is not equal.
# YOUR CODE

# Return the status.
return status

# The check_diag_sum function accepts a two-dimensional
# list as an argument, and returns True if the sum of
# the values in each of the list's diagonals are equal.
# Otherwise, it returns False.
def check_diag_sum(value_list):
# Initialize status to True.
status = True

# Calculate the sum of the values in the first diagonal.
sum_diag_0 = value_list[0][0] + \
value_list[1][1] + \
value_list[2][2]

# Calculate the sum of the values in the second diagonal.
#YOUR CODE

# Determine if the sum of any of the columns
# is not equal.
# YOUR CODE

# Return the status.
return status

# Call the main function.
main()


Grading

Lab assignment Grading Rubric
Criteria Approx. % of Grade Excellent (100%) Adequate (80%)  Poor (60%) Not Met (0%)
Program Specification /Correctioness 50%(10 points) No errors, program always works correctly and meets the specification(s). Minor details of the program specification are violated, program functions incorrectly for some inputs. Significant details of the specification are violated, program often exhibits incorrect behavior. Program only functions correctly in very limited cases or not at all.
Readability 20% (4 points) No errors, code is clean, understandable, and well-organized. Minor issues with consistent indentation, use of whitespace, variable naming, or general organization. At least one major issue with indentation, whitespace, variable names, or organization. Major problems with at three or four of the readability subcategories.
Documentation 10% (2 points) No errors, code is well-commented. One or two places that could benefit from comments are missing them or the code is overly commented. File header missing, complicated lines or sections of code uncommented or lacking meaningful comments. No file header or comments present.
Code Efficiency 15% (3 points) No errors, code uses the best approach in every case. No errors, code uses the working approach in every case.  Code uses poorly-chosen approaches in at least one place. Many things in the code could have been accomplished in an easier, faster, or otherwise better fashion.
Assignment Specifications 5% (1 point) No errors N/A Minor details of the assignment specification are violated, such as files named incorrectly or extra instructions slightly misunderstood. Significant details of the specification are violated, such as extra instructions ignored or entirely misunderstood.