Python Programming

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Python Programming

Post by answerhappygod »

Python Programming
Python Programming 1
Python Programming 1 (101.95 KiB) Viewed 35 times
Python Programming 2
Python Programming 2 (80.58 KiB) Viewed 35 times
Python Programming 3
Python Programming 3 (78.66 KiB) Viewed 35 times
18.6 Project 6: Magic Squares Summary A magic square is a square where the sums of the numbers in each row, each column, and both main diagonals are the same. We are going to write a program that determines whether a nested list is a magic square. You will write a program that contains a main scripting area to build a nested list from the user, and then four separate functions. The required functions are outlined below. The first three functions determine whether all rows, columns, or main diagonals of a nested list sum to a given value. The fourth function determines whether the nested list is a square. All four functions return either True or False depending on their determinations. Step 1. Write the row_check function. • The row_check function returns True or False. • The row_check function takes two parameters o The first parameter is a nested list of integers. o The second parameter is an integer value to compare all the sums to The function will return True when all the individual rows of the nested list sum to the provided value. Otherwise the function will return False Step 2. Write the scripting area to test the row_check function. • The scripting area should first acquire the magic number from the user as an integer. • Then the scripting area should acquire the number of rows in the nested list from the user. • After acquiring the number of rows, the scripting area should acquire all the data from the user to go into the specified number of rows • Finally, once all the user input is complete the scripting area should call the implemented functions to assess whether the entered nested list is a magic square or not and print out the appropriate message. Example Executions Typed user input for the following execution was: 14 3 2 6 6 9 5 1 4 3 8 What is the magic number? 14 How many rows of data? 3 Enter each row of data with values separated by spaces: 2 6 6 9 5 1 4 3 8 That is not a magic square.
That is not a magic square. Typed user input for the following execution was: 15 3 2 7 6 9 5 1 4 3 8 What is the magic number? 15 How many rows of data? 3 Enter each row of data with values separated by spaces: 2 7 6 9 5 1 4 3 8 You have a magic square! Step 3. Write the col_check function and add the call to the scripting area developed in Step 2 • The col_check function returns True or False • The col check function takes two parameters . The first parameter is a nested list of integers. o The second parameter is an integer value to compare all the sums to. The function will return True when all the individual columns of the nested list sum to the provided value. Otherwise the function will return False. Step 4. Write the diag_check function and add the call to the scripting area developed in Step 2. • The diag_check function returns True or False. • The diag_check function takes two parameters o The first parameter is a nested list of integers. • The second parameter is an integer value to compare all the sums to. The function will return True when both main diagonals of the nested list sum to the provided value. Otherwise the function will return False. When visualizing these two diagonals they always start with the first and last elements of the top row, but may not reach the bottom row or across all columns depending on the size and shape of the nested list.
The diag_check function returns True or False. • The diag_check function takes two parameters o The first parameter is a nested list of integers. o The second parameter is an integer value to compare all the sums to The function will return True when both main diagonals of the nested list sum to the provided value. Otherwise the function will return False. When visualizing these two diagonals they always start with the first and last elements of the top row, but may not reach the bottom row or across all columns depending on the size and shape of the nested list. Step 5. Write the is_square function and add the call to the scripting area developed in Step 2 • The is_square function returns True or False. • The is_square function takes one parameter o the only parameter is a nested list of integers The function will return True when the number of rows is equivalent to the number of columns in the nested list (making it a square) otherwise the function will return false. Step 6. Complete the scripting area to finalize the program. Typed user input for the following execution was: 34 4 4 14 15 1 9 7 6 12 5 11 10 8 16 2 3 13 What is the magic number? 34 How many rows of data? 4 Enter each row of data with values separated by spaces: 4 14 15 1 9 7 6 12 5 11 10 8 16 2 3 13 You have a magic square!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply