CSCI 102 - Intro to Computer Science LAB

Python Assignment

More on Lists

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

Home | Contact | Schedule | Assignments | Syllabus |

Week 07 Python Assignment
Due by Tuesday, October 12th, 2021
        Part A: CheckerBoard (must (1) demo during class (2) upload to Gradescope by 11:45pm)
        (No part B this week)


Welcome to your assignment for Week 07 of CSCI 102! Each week, after Studio, you should work on that week's homework assignment (lab). This lab is to be done on your own (not pair programming). It will be demoed in class on Tuesday and must be submitted to Gradescope no later than 11:45PM on the due date. Unlike CSCI 101, we will place all assignments for a given week on one HTML page. This is your Week 7 CSCI 102 Assignment page.

Good news: only ONE 102 lab assignment this week (mainly because the CSCI 101 lab is a bit long).

Checker Board (5 points)

Introduction

To get started, open IDLE and create a New File via the File menu. We suggest you immediately save this file in the directory managing all your 102 Python Labs this semester. Please save this file with the following name: Week7A-checkerboard.py.

Problem Statement

The purpose of this lab is to familiarize yourself with 2D arrays and how to create them in Python.
A checkerboard is a 8 x 8 square of alternating dark and light colors, as shown below:


Your task for this lab is to create a checkerboard generator, which takes as inputs n (the number of rows), m (the number of columns) and 2 elements and generates an n x m checkerboard with the two elements as alternating squares. For example, if n = 3 and m = 4 and the elements are a and b, the checkerboard would be:

[
 ['a', 'b', 'a', 'b'],
 ['b', 'a', 'b', 'a'],
 ['a', 'b', 'a', 'b']
]

Treat all inputs as strings. The first element should go in the upper left of the checkerboard.

Lab I/O Format

Throughout this semester we will use a specific Lab Input/Output Format. 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: ROWS>, COLUMNS>, FIRST>, and SECOND>.
  • When providing output that will be graded, start the line with OUTPUT. Think of this as "boxing your answer" on a math worksheet; it lets us quickly find your answer. Our grading script will skip any output lines that do not start with OUTPUT.
  • You are welcome (and should!) have other output lines that do not begin with OUTPUT; while our grading script will ignore these, good programmers include print statements that are informational to the user of the program.
  • A submission without exactly correct output formatting will recieve 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

How many rows does the checkerboard have?
ROWS> 3
How many columns does the checkerboard have?
COLUMNS> 4
What are the strings with which to pattern it?
FIRST> a
SECOND> b
A checkerboard with 3 rows, 4 columns, first string is a, and second string is b is:
OUTPUT ['a', 'b', 'a', 'b']
OUTPUT ['b', 'a', 'b', 'a']
OUTPUT ['a', 'b', 'a', 'b']
And the 2D array representation is:
OUTPUT [['a', 'b', 'a', 'b'], ['b', 'a', 'b', 'a'], ['a', 'b', 'a', 'b']]

Example Execution #2

How many rows does the checkerboard have?
ROWS> 4
How many columns does the checkerboard have?
COLUMNS> 4
What are the strings with which to pattern it?
FIRST> 67
SECOND> HA
A checkerboard with 4 rows, 4 columns, first string is 67, and second string is HA is:
OUTPUT ['67', 'HA', '67', 'HA']
OUTPUT ['HA', '67', 'HA', '67']
OUTPUT ['67', 'HA', '67', 'HA']
OUTPUT ['HA', '67', 'HA', '67']
And the 2D array representation is:
OUTPUT [['67', 'HA', '67', 'HA'], ['HA', '67', 'HA', '67'], ['67', 'HA', '67', 'HA'], ['HA', '67', 'HA', '67']]

Example Execution #3

How many rows does the checkerboard have?
ROWS> 8
How many columns does the checkerboard have?
COLUMNS> 5
What are the strings with which to pattern it?
FIRST> black
SECOND> white
A checkerboard with 8 rows, 5 columns, first string is black, and second string is white is:
OUTPUT ['black', 'white', 'black', 'white', 'black']
OUTPUT ['white', 'black', 'white', 'black', 'white']
OUTPUT ['black', 'white', 'black', 'white', 'black']
OUTPUT ['white', 'black', 'white', 'black', 'white']
OUTPUT ['black', 'white', 'black', 'white', 'black']
OUTPUT ['white', 'black', 'white', 'black', 'white']
OUTPUT ['black', 'white', 'black', 'white', 'black']
OUTPUT ['white', 'black', 'white', 'black', 'white']
And the 2D array representation is:
OUTPUT [['black', 'white', 'black', 'white', 'black'], ['white', 'black', 'white', 'black', 'white'], ['black', 'white', 'black', 'white', 'black'], ['white', 'black', 'white', 'black', 'white'], ['black', 'white', 'black', 'white', 'black'], ['white', 'black', 'white', 'black', 'white'], ['black', 'white', 'black', 'white', 'black'], ['white', 'black', 'white', 'black', 'white']]

Gradescope Submission Nuances

You will demo this lab in class on Tuesday and should also submit it to Gradescope after demoing in class. Because this is a demo lab, no tests will be run upon submission to Gradescope—your grade will be based on your performance in the demo. However, proper I/O formatting is still required.

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:
        #  Tracy Camp
        #  CSCI 102 – Section A
        #  Week 7 - Lab A - Checkerboard
        #  References: Used website to get more familiar with 2D lists
        #  References: https://snakify.org/en/lessons/two_dimensional_lists_arrays/
        #  Time: 45 minutes

Submit Solutions

Follow these steps to submit your file to Gradescope.
  • In Gradescope, go to CSCI 102 > Week7A and upload Week7A-checkerboard.py.
To receive full credit, your code must execute in Python 3, and you must submit a single file for each portion of the assignment (your Python code file). In addition, your code must follow the Lab I/O Format.

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.