write python3 code
CSCI 1170003
Open Lab Bonus 2 (OPTIONAL)
Due: Wednesday, December 2nd by 10:20am Assignment code: olab2
LAB GOALS:
● File Reading and Writing ● Iterating over 2D Lists
LAB DESCRIPTION:
You are going to write a program that validates a file containing a Sudoku solution.
Sudoku is a number game in which a 9x9 grid of numbers have the following properties: 1.) The numbers 1 through 9 only exist once each per row. 2.) The numbers 1 through 9 only exist once each per column. 3.) The numbers 1 through 9 only exist once each in a grid made up of 3x3 chunks. See below:
Your tasks for this program consist of the following:
1.) Prompt the user to enter the name of the file in which the sudoku solution exists.
2.) Open the file and read the solution into a 2D Python list.
3.) Write two functions that will take the 2D list as an argument and return True or False depending on the following conditions:
a.) A check_rows() function that takes the 2D list as an argument and checks that each row in the solution adds up to 45. If all 9 rows each add up to 45, you will return True. Otherwise, you will return False and print out lines explaining which rows failed the test. For example: “Failed on Row 3”
b.) A check_columns() function that takes the 2D list as an argument and checks that each column in the solution adds up to 45. If all 9 columns each add up to 45, you will return True. Otherwise, you will return False and print out lines explaining which columns failed the test. For example: “Failed on Column 3”
4.) Your main function should then print a message whether the solution passed or failed the above tests.
5.) Your main program logic should be inside a main() function, and all functions should be defined in Hierarchical Order, with comments describing each function.
The test files used in the examples shown below can be copied from my shared drive:
cp ~mcm7f/shared/sudoku1.dat .
cp ~mcm7f/shared/sudoku2.dat .
cp ~mcm7f/shared/sudoku3.dat .
cp ~mcm7f/shared/sudoku4.dat .
CSCI 1170003
Open Lab Bonus 2 (OPTIONAL)
Due: Wednesday, December 2nd by 10:20am Assignment code: olab2
The Sudoku solution file will be 9 rows of 9 digits with no spaces between them, as shown in the example below:
534678912 672195348 198342567 859761423 426853791 713924856 961537284 287419635 345286179
EXAMPLE OUTPUT
$ python3 olab2.py Enter name of test file: sudoku1.dat Sudoku Passes tests! $ python3 olab2.py Enter name of test file: sudoku2.dat Failed on row 3 Failed on row 4 Sudoku Failed tests. $ python3 olab2.py Enter name of test file: sudoku3.dat Failed on column 6 Failed on column 7 Sudoku Failed tests. $ python3 olab2.py Enter name of test file: sudoku4.dat Failed on row 5 Failed on column 3 Sudoku Failed tests.
Please do you own work on this lab. If there are any questions, please contact your instructor for clarifications.
CSCI 1170003
Open Lab Bonus 2 (OPTIONAL)
Due: Wednesday, December 2nd by 10:20am Assignment code: olab2
HOW TO TURN IN:
There will be THREE components used in determining the grade for this lab.
1.) Save your python script as ‘ olab2.py ’ in your OLA directory. You must submit your olab2.py file using turnin (instructions below) by Wednesday, December 2nd by 10:20am . Late files will NOT be accepted, and only your submitted program will be tested and graded.
2.) Hand in a printed copy of your olab2.py file. 3.) Hand in a selfgraded copy of this lab’s rubric (located on the last page).
USING TURNIN:
Once you are ready to submit your olab1.py file, you will need to use the turnin command. 1.) In the UNIX terminal, navigate to the same directory as your olab1.py file. 2.) At the $ UNIX prompt, to submit your program you should type:
turnin mcm7f olab2 olab2.py
Notes: To verify that you have submitted successfully, you may type the command: turnin mcm7f olab2
If you see the response:
project code: olab2 due date and time: 20151202 10:20 userid: <your id> file not found (not yet submitted)
Then your file was not successfully submitted.