CSCI 102 - Intro to Computer Science LAB

Python Assignment

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

Home | Contact | Schedule | Assignments | Syllabus |

Week 08 Python Assignment
Due by Tuesday, October 26th, 2021
        Part A: Rolling a Die (must (1) demo during class and (2) upload to Gradescope by 11:45pm)
        Part B: Combing Through a Haystack (due to Gradescope by 11:45pm)


Welcome to your assignment for Week 08 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 8 CSCI 102 Assignment page.

You have TWO problems to do this week, the first of which (Part A) you will demo in class with a TA on Tuesday and both of which you will SUBMIT to Gradescope. Details on Part A and Part B are below.

Part A: Rolling a Die (3 points)

Introduction

To get started, open IDLE and then create a New File via the File menu. We suggest you immediately save this file in the directory you created to manage all your Python Labs this semester (e.g., CSCI102/PythonLabs). Save this file as Week8A-rolling_die.py.

In this lab we practice randomly generating numbers by rolling one die of a specified number of sides. That is, if your program rolls a 6-sided die 6000 times, you should get approximately 1000 ones, 1000 twos, etc. Use a list to count the number of times a die is rolled, given the user wants the M-sided die rolled N times.

You can assume the input to your program is always valid (i.e., the number of rolls entered is a positive number). You should also seed your random number generator so that results can be replicated.

HINT: be sure to watch Python Video #14: RNG (Random Number Generation), if you are unsure how to get started.

Lab I/O Format

Thoughout 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, your WORD in this lab might be: SIDES>, ROLLS> 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. 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.

Example Execution #1

Input the number of sides of the die:
SIDES> 6
Input the number of rolls to make:
ROLLS> 6
Input the seed for the random number generator:
SEED> 0

Your 6 rolls of a 6-sided die follow:
OUTPUT 1 occurred 1 times
OUTPUT 2 occurred 0 times
OUTPUT 3 occurred 1 times
OUTPUT 4 occurred 3 times
OUTPUT 5 occurred 1 times
OUTPUT 6 occurred 0 times

Example Execution #2

Input the number of sides of the die:
SIDES> 5
Input the number of rolls to make:
ROLLS> 60000
Input the seed for the random number generator:
SEED> 123456

Your 60000 rolls of a 5-sided die follow:
OUTPUT 1 occurred 11963 times
OUTPUT 2 occurred 11996 times
OUTPUT 3 occurred 11954 times
OUTPUT 4 occurred 12018 times
OUTPUT 5 occurred 12069 times

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 G
        #   Week 8 - Lab A - Rolling a Die
        #   References: None
        #   Time: 25 minutes

Part B: Combing Through a Haystack (5 points)

Introduction

Bioinformatics is the science of collecting and analyzing complex biological data such as genetic codes.

To get started, read the details for the Combing Through the Haystack project on the Rosalind site. Then, open IDLE and create a New File via the File menu. We suggest you immediately save this file in the directory you created to manage all your Python Labs this semester (e.g., CSCI102/PythonLabs). Save this file as Week8B-haystack.py. You will have the following input/output in this project:

Input: Two DNA strings s and t, each of length at most 1000 characters long. The string t must also be no longer than the string s.

Output: Total number of substrings t within s and all locations of t as a substring of s. Or, if t is longer than s, print an error message to the user and output ERROR (shown in example execution #2).

HINT: note that the location of a substring in the example below does not equal the index in the string. That is, the index in the string is 0-based to computers while a location within an array is 1-based to most humans. You should, therefore, use 1-based in your output.

HINT2: The Rosalind site has several datasets that you can use to test your code.

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: s> and t>.
  • 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.

Example Execution #1

Enter a DNA string s:
s> GATATATGCATATACTT
Enter a substring t:
t> ATAT
The total number of substrings found is 3
OUTPUT 3
The locations of these substrings in s are: 2 4 10
OUTPUT 2 4 10

Example Execution #2

Enter a DNA string s:
s> GATA
Enter a substring t:
t> ATATACTT
Error: Substring is longer than DNA string
OUTPUT ERROR

Gradescope Submission Nuances

Part B will ONLY be submitted to Gradescope (you will NOT demo this lab in class).
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 receive 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:
        #   Tracy Camp
        #   CSCI 102 – Section B
        #   Week 8 - Lab B - Combing Through a Haystack
        #   References: Roommate Spider Man for help with calling string functions
        #   Time: 35 minutes

Submit Solutions

Follow these steps to submit your files to Gradescope.
  1. In Gradescope, go to CSCI 102 > Week8A and upload Week8A-rolling_die.py.
  2. In Gradescope, go to CSCI 102 > Week8B and upload Week8B-haystack.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.