CSCI 102 - Intro to Computer Science LAB

Python Assignment

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

Home | Contact | Schedule | Assignments | Syllabus |

Week 09 Python Assignment
Due by Tuesday, November 2nd, 2021
        Part A: Word Search (must 1) demo in class and 2) submit to Gradescope by 11:45 pm)
        (No part B this week)


Welcome to your assignment for Week 09 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), and needs to be completed and 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 9 CSCI 102 Assignment page.

Only ONE assignment this week!

Word Search (4 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: Week9-word_search.py.

Problem Statement

For this lab, you'll need this dictionary.txt file in the same directory as where you are developing the Python code for this lab. This file contains 127,142 English words (where each word is placed on a new line). Your task is to write a program that has the user input an integer, which represents the length of a word the user desires. Your code should then output to the console (1) the number of words in the dictionary that have the same length as the user input and (2) a random word of that length. Specifically:
    • Read in the dictionary file.
    • Prompt the user to enter the word length of interest (i.e., N).
    • Prompt the user to enter a seed for random (i.e. SEED).
    • Output the number of words in the dictionary that have length N.
    • Seed the random function with SEED.
    • Of the words that have length N, choose one word randomly and output it.
If there are no words of length N, output "None".

Lab I/O Format

Throughout this semester we will often 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: LENGTH> and SEED>.
  • 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.
  • 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 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 (depending on your implementation, your lab may not choose "trivia")

Enter the length of the words to find:
LENGTH> 6
Enter the seed to use:
SEED> myseed!
The number of words with length 6 is:
OUTPUT 14383
Here is one random word with length 6:
OUTPUT dimmer

Example Execution 2

Enter the length of the words to find:
LENGTH> 29
Enter the seed to use:
SEED> 29
The number of words with length 29 is:
OUTPUT 1
Here is one random word with length 29:
OUTPUT floccinaucinihilipilification

Example Execution 3

Enter the length of the words to find:
LENGTH> 45
Enter the seed to use:
SEED> cucumber
The number of words with length 45 is:
OUTPUT 0
There are no words of length 45 in the dictionary.
OUTPUT None

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:
        # John Henke
        # CSCI 102 – Section B
        # Week 9A - Word Search
        # References: Instructor Hunter for file reading and TA Katy for random number generation
        # Time: 25 minutes

Submit Solutions

Follow these steps to submit your solution to Gradescope.
  • In Gradescope, go to CSCI 102 > Week9A and upload Week9-word_search.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.