Computers and Technology, 05.05.2020 13:48, quokkamokka97
There is a simple method for constructing a magic square for any odd value of n:
Make a blank n by n grid. We need to populate it with the integers from 1 to n2.
Set i to 1.
Set the current grid position to the location in the middle of the top row.
Insert the number i into the current grid position.
If i is equal to n2, we're done.
If i is a multiple of n, move the current grid position down one (i. e., in the direction of "south" on a map). Otherwise, move the current grid position diagonally up and right (i. e., in a "northeast" direction on a map), wrapping to the first column or last row if the move leads outside the grid.
Increment i by 1.
Return to step 4.
In this assignment, you will create a class of MagicSquare objects, and print out magic squares with sides 1, 3, 5, 7, 9, 11, and 13.
The class MagicSquare should have two properties:
sideLength, an integer representing how many numbers are in each row and column of the magic square.
grid, a two-dimensional list of size sideLength by sideLength representing the contents of the magic square.
The class MagicSquare should have two methods:
__init__(), which takes as an argument an integer side representing the value for the new object's sideLength. __init__ should create the two-dimensional list grid and initially populate it with zeroes. __init__ should then use the algorithm described above to replace the zeroes in grid with the integers from 1 to sides2.
display(), which prints out a MagicSquare object. It should print out each number in a field of size 5, right-justified, similar to the example above. It should also print a blank line after the magic square.
Create a main program that uses a loop to print the seven magic squares listed above, each preceded by the title, "Magic Square of size ", followed by the corresponding value for side. Leave a blank line between the title and the magic square. See the example above.
Answers: 3
Computers and Technology, 23.06.2019 15:30, jokerr6323
1. ask the user how many questions are in the quiz. 2. ask the user to enter the key (that is, the correct answers). there should be one answer for each question in the quiz, and each answer should be an integer. e. g., 34 7 13 100 81 3 9 10 321 12 might be the key for a 10-question quiz. you will need to store the key in an array. 3. ask the user to enter the answers for the quiz to be graded. there needs to be one answer for each question. note that these answers do not need to be stored; each answer can simply be compared to the key as it is entered. 4. when the user has entered all of the answers to be graded, print the number correct and the percent correct. 5. add a loop so that the user can grade any number of quizzes with a single key. after the results have been printed for each quiz, ask "grade another quiz? (y/n)." note: you only have one array (the key). you are not creating a new key for each set of quiz answers.
Answers: 3
Computers and Technology, 24.06.2019 07:40, daebreonnakelly
What type of multimedia are live news feeds? live news feeds are examples of multimedia.
Answers: 2
There is a simple method for constructing a magic square for any odd value of n:
Make a...
Make a...
Biology, 17.10.2020 22:01
English, 17.10.2020 22:01
Physics, 17.10.2020 22:01
Mathematics, 17.10.2020 22:01
Mathematics, 17.10.2020 22:01
Social Studies, 17.10.2020 22:01
Mathematics, 17.10.2020 22:01