Lists, tuples, sorting, and slicing.
In this lab, you will implement functions that clean, summarize, sort, and slice score data. You will practice using lists for ordered, changeable data and tuples for immutable summary results.
You will complete the code in:
src/score_summary.py
Do not change function names, parameter names, file names, or test file names unless your instructor tells you to. The tests and Classroom50 autograder import these exact functions.
By the end of this lab, you should be able to:
- Store ordered values in Python lists.
- Convert and clean mixed input values.
- Sort data without modifying the original list.
- Use slicing to select the highest, lowest, or middle values.
- Return immutable summary information as a tuple.
- Run pytest before committing and pushing your work.
- Submit a clear Canvas lab post with GitHub evidence.
- Complete peer review through a GitHub pull request.
-
Open the Classroom50 assignment link from this Canvas module and accept the assignment.
-
Click Go to your GitHub repository to open your assignment repository in a new browser tab.
-
Open NRP JupyterHub.
-
Start your JupyterHub server using the course settings: 0 GPUs, 2 CPU cores, 4 GB Memory, Stack Minimal.
-
If you have not already connected JupyterHub to GitHub with SSH, generate an SSH key in a JupyterHub terminal:
ssh-keygen -t ed25519
Press Enter three times to use the default location and skip a passphrase.
-
Print and copy your public key:
cat ~/.ssh/id_ed25519.pub -
Add the SSH public key to your GitHub account at https://github.com/settings/keys.
-
Return to your GitHub repository browser tab, click the green Code button, choose SSH, and copy the clone URL.
-
In a JupyterHub terminal, clone your repository:
cd ~/ git clone PASTE_YOUR_SSH_CLONE_URL_HERE cd REPOSITORY_FOLDER_NAME
-
Confirm you are in the repository root folder:
pwd lsYou should see files such as
README.md,pyproject.toml,src, andtests. -
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate -
Install the project and test tools:
python -m pip install -e .[test]
-
Run the tests before editing so you can see what currently fails:
python -m pytest -q
-
Edit only the permitted source file:
src/score_summary.py -
Run tests until they pass:
python -m pytest -q
-
Commit and push your completed work:
git status git add src/score_summary.py git commit -m "Complete week 2 score summary lab" git push origin main -
Go back to your GitHub repository, click the Actions tab, and confirm the autograder result after it runs.
-
Grant the GitHub Team
classroom50-cisc217-inter-python-programmingthe role Read on your repository if peer review access is not already available. -
Post your GitHub repository link and required evidence in the Canvas lab discussion.
Complete all functions in score_summary.py.
Return a list of valid numeric scores between 0 and 100, inclusive.
Rules:
- Accept integers and floats.
- Accept strings that can be converted to numbers, such as
"88"or"91.5". - Ignore
Nonevalues. - Ignore values that cannot be converted to numbers.
- Ignore numeric values below 0 or above 100.
- Return scores as floats in their original valid order.
Example:
clean_scores(["90", None, -5, "abc", 87.5, 105])
# returns [90.0, 87.5]Return an immutable summary tuple in this exact order:
(count, lowest_score, highest_score, average_score)Rules:
- Convert numeric results to floats except for
count. - Round the average to 2 decimal places.
- For an empty list, return
(0, 0.0, 0.0, 0.0).
Example:
summarize_scores([80, 90, 100])
# returns (3, 80.0, 100.0, 90.0)Return a new sorted list of scores.
Rules:
- Convert returned values to floats.
- Do not modify the original list.
- By default, sort from highest to lowest.
- If
descendingisFalse, sort from lowest to highest.
Return the highest scores as an immutable tuple.
Rules:
- Use sorting and slicing.
- If
countis larger than the number of scores, return all available scores. - If
countis0or negative, return an empty tuple.
Return the lowest scores as an immutable tuple.
Rules:
- Use sorting and slicing.
- If
countis larger than the number of scores, return all available scores. - If
countis0or negative, return an empty tuple.
Return a tuple with the lowest and highest score removed.
Rules:
- Sort scores from lowest to highest first.
- Remove one lowest score and one highest score using slicing.
- Return the remaining values as an immutable tuple.
- If fewer than 3 scores are provided, return an empty tuple.
Example:
middle_scores([70, 100, 80, 90])
# returns (80.0, 90.0)Return a new list with points added to each score, capped at 100.
Rules:
- Do not modify the original list.
- Add
pointsto every score. - Scores may not go above 100.
- Return values as floats.
Example:
curve_scores([91, 98], 5)
# returns [96.0, 100.0]Run:
python -m pytest -qA passing run should show output similar to:
11 passed
The exact number of tests may change if your instructor updates the assignment, so pay attention to whether all tests pass.
After your tests pass and you push your work to GitHub, post in the Week 2 Lab Discussion.
Your initial post should include:
- A link to your GitHub/Classroom50 repository.
- A short explanation of how you used lists in this lab.
- A short explanation of where you returned tuples and why tuples make sense for that result.
- One example of sorting or slicing from your solution.
- One question, challenge, or debugging issue you encountered.
Example initial post:
My repository is here: PASTE_LINK_HERE. In my solution, I used lists for score data because the functions need to clean, sort, and slice ordered values. I returned tuples from
summarize_scores,top_scores,bottom_scores, andmiddle_scoresbecause those results should not be changed after they are created. One place I used slicing was inmiddle_scores, where I sorted the values and then used a slice to remove the first and last score. One issue I had was remembering thatsorted()returns a new list while.sort()changes the original list.
Your peer review is completed through a GitHub pull request and a Canvas reply in the same lab discussion board.
The peer review is due one week after the initial lab post is due.
Open a pull request on a classmate's repository. Your pull request should make a small, helpful contribution. For Week 2, this should usually be a documentation or test-comment improvement, such as:
- Fixing a typo or unclear sentence in the README or a documentation file.
- Adding a short comment that makes a list, tuple, sorting, or slicing step easier to understand.
- Suggesting a clearer explanation of the test output.
- Asking a thoughtful question in the pull request description about one of the Week 2 concepts.
Do not rewrite your classmate's solution or make unrelated changes. The goal is to practice professional code review, communication, and GitHub collaboration.
In the same Canvas discussion board, reply to your classmate with:
- A link to the pull request you opened.
- One specific comment about their use of lists, tuples, sorting, or slicing.
- One specific suggestion or question connected to their repository or test evidence.
Replies such as "Good job," "I agree," or "Looks good" by themselves are not substantial enough for credit.
Example peer review reply:
Hi Jordan, here is the pull request I opened on your repository: PASTE_PULL_REQUEST_LINK_HERE. I noticed that your
top_scoresfunction uses sorting before slicing, which makes the result easier to reason about. I suggested adding one short comment explaining why the function returns a tuple instead of a list. One question I had was whether yoursort_scoresfunction changes the original list or returns a new sorted list, because that distinction is important for this week's topic.
You may discuss setup steps, error messages, and general Python concepts with classmates. Your submitted code must be your own work. Do not copy another student's solution. Peer review pull requests should be small, helpful improvements rather than replacement solutions.