CSCI 101 - Intro to Computer Science

Python Lab

Quick Links: zyBook | Piazza | Canvas | CS @ Mines

Home | Contact | Schedule | Assignments | Syllabus |

Python Lab 4: Tic-Tac-Toe Solver
Due Tuesday, September 28th, by 11:45pm


Introduction

Welcome to your fourth Python lab in CSCI 101! This week, we'll have one lab, which is due before the due date/time. You should submit this lab as a single .py file. For those NOT in CSCI 102, check out the CSCI 102 Schedule to see what was covered this week (if needed).

To get started, open IDLE and then create a New File via the File menu. We suggest you immediately save this file in some directory you create that you will use to store/manage all your Python Labs this semester (e.g., CSCI101/PythonLabs). Save this file as Lab4-tictactoe.py.

Assignment

After years of planning, you’re finally ready to host the Tic-Tac-Toe world championships. Everything had been going great until you made a terrible discovery: the judges, who determine which player has won the game, have been taking bribes! There’s not enough time to train new ones, so you opt for a backup plan: you’ll create a piece of code that analyzes the board and tells the players if anyone has won. A Tic-Tac-Toe board looks like the following. Every square can be empty, filled with an X, or filled with an O (capital letter ‘o’). Player X has won if they have three X’s in a row. Player O wins if they can do the same with the O’s. A row can be horizontal, vertical, or diagonal. Can you write the new judging code and salvage the competition?

Input

The input consists of three lines each with 3 characters. Each line represents a row on the board. Each character in a line represents a column. This means you have 3 rows and 3 columns, just like a normal Tic-Tac-Toe board. Each square in the board contains either an X, O (that’s a capital letter, not a number), or E. X and O represent markings made by the players while E represents an empty square.

Output

If player X has won, you should print out the character X. If player O has won, you should print out the character O. If neither player has won, you should print out the character N.

Lab I/O Format

For lab assignments this semester, a specific Lab Input/Output Format is required. This format is described below:
  • When prompting for input, use the prompt string WORD>, where WORD is a single, uppercase word which describes the input. For example, this lab might choose: ROW> .
  • When providing output that will be graded, start the line with the word OUTPUT followed by exactly one space, e.g. OUTPUT . Think of this as "boxing your answer" on a math worksheet; it lets us quickly find your answer. Gradescope will skip any output lines that do not start with OUTPUT.
  • You are welcome to have other output lines that do not begin with OUTPUT; Gradescope will ignore these.
  • A submission without exactly correct output formatting will receive an AUTOMATIC ZERO. This is because Gradescope is automated—it does not look at your code, only the results, and thus the format of the results must be consistent for all students.
Example Execution 1:
ROW0> XEO
ROW1> EXO
ROW2> EOX
OUTPUT X

Example Execution 2:
ROW0> OXO
ROW1> OXX
ROW2> XOX
OUTPUT N

Example Execution 3:
ROW0> XXE
ROW1> EXX
ROW2> OOO
OUTPUT O

Gradescope Submission Nuances

When you submit your Python file to Gradescope, multiple different test cases are run on your code. Passing all of the tests results in a 100% on the autograded portion of the lab.

You are allowed to submit to Gradescope four times (or less) for this lab. The maximum grade of your submissions will be your grade for the lab. Note: If your code doesn’t work (e.g., a syntax error exists, or an error is thrown in execution), then you will received an AUTOMATIC ZERO. You should test your code before submitting to ensure it executes correctly.

Comments

All Python files should include a header with your name, section, assignment info, references (i.e., who did you collaborate with on this assignment?; what resource did you use?), and approximate time taken to do the assignment. Be sure to cite any allowed external references used to complete the assignment. Any code without this header will lose 1 point. Here's an example:
        #   John Henke
        #   ​CSCI 101 – Section D
        #   Python Lab 4
        #   References: TA Gabriel for pseudocode help.
        #   Time: 50 minutes

Submission

Once you are satisfied with your solution to this lab, you need to submit the file to Gradescope. In Gradescope, go to Assignments > Lab4 and upload Lab4-tictactoe.py.

Note: this lab is worth 8 points. To receive credit, your code must execute in Python 3, you must submit a single file (your Python code file), and you must have the input/output match the lab requirements.

Whenever you submit something to Gradescope, we strongly recommend you always double check what you submitted actually got submitted correctly (e.g., did the file upload correctly? did you submit the correct file? etc.) If your submission is incorrect, it's on you.




Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0