Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / CS119 Python Programming PJ 11 - Sudoku Game Check   Please write a Python program to check a Sudoku game and show its result in detail

CS119 Python Programming PJ 11 - Sudoku Game Check   Please write a Python program to check a Sudoku game and show its result in detail

Computer Science

CS119 Python Programming

PJ 11 - Sudoku Game Check

 

Please write a Python program to check a Sudoku game and show its result in detail. This is an application program of using 2-dimensional arrays or lists.   Each array or list is a game board of 9 x 9.  Your program must check the 9 x 9 game board, and report all the problems among 9 rows, 9 columns, and 9 squares.

 

As you can see, you must pre-load the following four games into your arrays or lists.   Please create four lists of 9 x 9 each, and call them S1, S2, S3, and S4 respectively. 

The complete output of your 4 games must look exactly as follows including the data.

 

Welcome to play the Sudoku Game Check of "Dr. Simon Lin"!   ç Must put your name

1===================================.

Your game 1 is as follows:

123456789

234567891

345678912

456789123

567891234

678912345

789123456

891234567

912345678

 

Your game 1: 

Square 1 has a problem. 

Square 2 has a problem. 

Square 3 has a problem. 

Square 4 has a problem.

Square 5 has a problem. 

Square 6 has a problem. 

Square 7 has a problem. 

Square 8 has a problem. 

Square 9 has a problem.

 

2===================================.

Your game 2 is as follows:

123456789

456789123

789123456

234567891

567891234

891234567

345678912

678912345

912345678

 

Your game 2: 

Congratulations! You won the game.

 

3==================================.

Your game 3 is as follows:

123456782

456789123

789123456

234567891

567891234

891234567

345678912

678912345

912345678

 

Your game 3:  

Row 1 has a problem. 

Column 9 has a problem. 

Square 3 has a problem.

 

4===================================.

Your game 4 is as follows:

123456789

456789123

789123456

234567891

567891234

891234567

345678912

678918345

912345678

 

Your game 4: 

Row 8 has a problem. 

Column 6 has a problem. 

Square 8 has a problem.

 

5===================================.

Thank you for playing this Sudoku Game Check of "Dr. Simon Lin"!  ç Must put your name                                                           

6===================================.

------------------------------------------------------------------------------------------------------------------------.

Some structured programming design techniques:

 

[A] Your S1 (for Game 1) may be defined as follows:  

 

# Nice to show row index 0 to 8 and column index 0 to 8 for readability of your code

         S1 = [                                                 # Game 1

 # column index:        0 1 2 3 4 5 6 7 8    

                                   [1,2,3,4,5,6,7,8,9],    # Python row 0    ||  User’s row  1

                                   [2,3,4,5,6,7,8,9,1],    #                      1                            2

                                   [3,4,5,6,7,8,9,1,2],    #                      2                            3

                                   [4,5,6,7,8,9,1,2,3],    #                      3                            4

                                   [5,6,7,8,9,1,2,3,4],     #                     4                            5

                                   [6,7,8,9,1,2,3,4,5],     #                     5                            6

                                   [7,8,9,1,2,3,4,5,6],     #                     6                            7

                                   [8,9,1,2,3,4,5,6,7],     #                     7                            8

                                   [9,1,2,3,4,5,6,7,8]   ]  #                     8                            9

   # Python column    0 1 2 3 4 5 6 7 8

   # User’s column     1 2 3 4 5 6 7 8 9

 

----------------------------------------------------------------------------------------------------------------------.

[B] Your main program may have the following code to drive your game 1.

 

n = 1  # line number for each separation line for readability

print( )

print(n,"=============================================================");n=n+1;

print("Your game 1 is as follows: " )

showGame(S1)   # to print 9x9 game board

print( )

print(n,"=============================================================");n=n+1;

print("Your game 1: ")  # show the check result

checkGame(S1)  # to check 9 rows/columns/squares. Total 27 checkings.

print( )

print(n,"=============================================================");n=n+1;

 

You may have similar code to drive your game 2 to 4.

--------------------------------------------------------------------------------------------------------------------------.

 

[C] Your checkGame( ) function must call the following 3 functions:

 

RowOK(S1, row) to check row: 0 through 8 (meaning Row 1 through 9 from user’s view).

ColumnOK(S1, column) to check column: 0 through 8 (meaning Column 1 through 9 from user’s view).

SquareOK(S1, square) to check square: 0 through 8 (meaning Square 1 through 9 from user’s view).

-----------------------------------------------------------------------------------------------------------------------------.

 

[D] Your checkGame( ) function may look as follows:

 

def checkGame(S):   # check game board S for 9 rows, 9 columns, 9 squares

    countBad = 0   # count how many problems being detected

    for r in range(9):  # 9 rows check with r = 0 to 8

        if (not RowOK(S, r) ):     # r = 0 to 8 from computer’s view

            print("Row ", r + 1 , " has a problem.")               # Row 1 to 9 from user’s view

            countBad += 1   # increment countBad by 1

    for c in range(9):   #  9 columns check: 0 to 8, actually they mean column 1 to 9 for user.

        # more your coding here ###################    if (not ColumnOK(S, c) ):

    for q in range(9):  #  9 squares check: 0 to 8, actually they mean square 1 to 9 for user.

        # more your coding here ###################    if (not SquareOK(S, q) ):

    if countBad == 0:  # perfect game since nothing is bad

        print("Congratulations! You won the game.")

----------------------------------------------------------------------------------------------------------------------.

 

[E] Your RowOK( ) function may look as follows:

 

def RowOK(S, r):  # check Row r in S board is OK or not

    goodlist = [1,2,3,4,5,6,7,8,9]   # a perfect list of 1 thru 9 sorted order

    slist = S[r]     # get row r, which can be 0, 1, …, or 8

    clist = [ ]        # We must make a real copy of the original source list to avoid changing it here.

    for element in slist:

        clist.append(element)   # make a real copy to avoid side effect to the original 9x9 array

    clist.sort( )    # sort the list before comparing with goodlist

    return (clist == goodlist)    # true means OK for row r in S since they are equal

    # end of RowOK( )

 

Your ColumnOK(S, c) and SquareOK(S, q) functions are similar to RowOK(S, r) function.

--------------------------------------------------------------------------------------------------------------------------.

[F1] How to define Slist1 to be Square 1?

 

Slist1=[S[0][0],S[0][1],S[0][2],S[1][0],S[1][1],S[1][2],S[2][0],S[2][1],S[2][2]]  # Square 1 (red)

 

[F2] How to define Slist9 to be Square 9?

 

Slist9=[S[6][6],S[6][7],S[6][8],S[7][6],S[7][7],S[7][8],S[8][6],S[8][7],S[8][8]]  # Square 9 (purple)

 

The above hard-coded statements are easier ways to define Square 1 and 9.  You may use a nested for loops to define any of the 9 squares.

 

======================================================================.

How to submit your Project Assignment (PJ)?

(1) Each program must be well documented with block comments and proper line comments. 

     The beginning of each program must have a block comment to show its author, date, and purpose.

     The following is an example of block comments:

# Author:  _______________   ç  must use your full name here!

# Date:      _________                ç  must put today’s date here!

# Purpose: _______________   ç  must show the purpose of this program here!

(2) You must submit to Canvas the following two items as attachments:

       (a) Your source program (for example, CS119-PJ11.py ), and

       (b) Your WORD document (for example, CS119-PJ11-report .docx ) containing the listing of

             your Python program, and the complete output of your 4 games as shown above.           

       You must not submit a zip file to Canvas.

=========================================================================.

//You must delete everything above & including this line to make this your Word document to be submitted.

 

 

PJ 11 Report                                  My Name: ______________

 

A. The following is my Python source program:

       // Please copy your source program into here from your Visual Studio IDE.   

       // Your code here must be in color.  You must not show screen prints here.

 

B. The following is the console output of my 4 games:

     // One way to copy the console output is to press Ctrl+Alt+PrtScn. 

     // Another way to copy is to use the snipping tool.  To paste the image is to press Ctrl+v.

    // The console display must not be too wide, otherwise it will be too hard to read once pasted.

     // Please make sure your console is long enough to show all your output lines to be captured.

     // Please copy your console output and paste into here:

 

Game 1:

 

Game 2:

 

Game 3:

 

Game 4:

 

Option 1

Low Cost Option
Download this past answer in few clicks

18.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE