DATA/CPSC 350 — Applications of Databases — Spring 2026

Assignment #0 — Python practice

Possible experience: +20XP

Due: Monday, Feb. 2nd, midnight

Overview

For those of you new to Python — or those whose Python is rusty enough to possibly cause you trouble on the assignments for this class — this homework can be part of the remedy.

The Python tutorial

Go to the official Python tutorial, and make sure that the drop-down box at the top says "3.something". (3.14.2 is good, for instance.) Then, read the following sections:

(I'm not discouraging you from reading any of the other sections as well if you're interested. The above is a "must have" list, though. If you know those sections, I think that's a minimally sufficient set and you'll be good to go for this semester.)

Getting some practice

Setup

Download this file to your machine, then open it in vim. (Caution! Some of you will be tempted at this point to use a more familiar editor such as Spyder, Visual Studio, or Notepad++ instead of vim. Resist this temptation!! You'll be using vim all semester, because you'll be writing code on a server, and vim (or another text editor like emacs or nano) is the preferred solution for doing that. Part of this assignment's purpose is to do reps and build muscle memory for using the actual tools that you'll actually be using for the actual class. Avoiding the tools defeats much of the purpose.)

Now create a new file called myumwnetid_pythonpractice.py, where myumwnetid should be replaced by your real-life UMW NetID. (For example, jsmith19_pythonpractice.py would be a legit name.) Please do not get creative in naming this file. Do not capitalize your Net ID, or invent a new Net ID, or omit the underscore, or change the underscore to a dash or a space, or do anything else creative, period. Just call it myumwnetid_pythonpractice.py, where myumwnetid is replaced by your actual UMW NetID. Thanks.

Then, from the command line, run:

python pythonpractice.py myumwnetid

with "myumwnetid" once again changed to your actual UMW Net ID. Verify you can see a message with this line at the end:

... You've earned 0/20 XP!

You are now ready to actually start writing Python code.

Building strength and muscle memory

In your myumwnetid_pythonpractice.py file, add the following variables and functions, in any order:

  1. A variable called HAL whose value is the integer 9000.
  2. A variable named Bridge whose value is the string containing only the digit 4.
  3. A variable called Nahn whose value is a list containing the integer 2.
  4. A variable called R2 whose value is a list with elements D and 2, both strings.
  5. A variable named C which is a list with one element. That element is a set whose only element is the string "3PO".
  6. A set called Poppins that contains all the unique lower-case letters from the string "supercalifragilisticexpialidocious". (You should be able to do this without having to sift through the word and manually compute all the duplicates by hand yourself.)
  7. A variable named WALL which is a list of one element. That element is also a list. That (internal) list contains one element: the string with the letter E.
  8. A variable named K which is a set with one element: the string 2SO.
  9. A dictionary Galactica that contains the following key/value pairs (all strings):
  10. KeyValue
    KarlHelo
    KaraStarbuck
    LeeApollo
  11. After creating your Galactica dictionary with the above three key/value pairs, add code using the [] notation that adds the following additional two key/value pairs to it:
  12. KeyValue
    SharonBoomer
    MargeRacetrack
  13. A variable Wheel which is a dictionary with strings as keys and lists as values. Begin by adding these keys and values to it:
  14. KeyValues (in list)
    BlueMoiraine, Siuan
    GreenAlanna
    Purple(nothing)
    WhiteSarene
    Yellow(nothing)
    Plaid(nothing)
    RedElaida, Liandrin
  15. Then, after creating your Wheel dictionary with the above values, write code to make the following changes to it:
    1. Add a new key value pair: the key should be Brown and the value should be a list with Verin, Saerin, and Janya, in that order.
    2. Append the string Egweyne to the end of the Green list.
    3. Remove Liandrin from the Red list.
    4. Add Nynaeve to the Yellow list.
    5. Delete the Plaid key/value pair altogether.
  16. A variable Germanna_levels that contains a list of the two strings Freshman and Sophomore.
  17. A variable UMW_levels that contains a list of the four strings Freshman, Sophomore, Junior, and Senior.
  18. A variable MaryWash_levels which refers to the same list that UMW_levels refers to.
  19. A variable CNU_levels which, although referring to a list with the identical contents as the UMW_levels list, is nevertheless a different list object.
  20. A one-argument function called plus2 that takes a numeric argument and returns that argument added to the number 2.
  21. A function called gimme_dat_set that takes no arguments and returns a set containing the strings Navani, Shallan, and Jasnah. Each time gimme_dat_set() is called, it should return the same set object.
  22. A function called gimme_set_like_dat that takes no arguments and returns a set containing the strings Kaladin, Dalinar, and Adolin. Unlike gimme_dat_set(), every time gimme_set_like_dat() is called it should return a different set object (with the same contents).
  23. A function center that takes one argument, a string. If that string is the empty string, center should return None. If the argument has an odd number of letters, the method should return the one in the exact middle. If the argument has an even number of letters (greater than 0), the method should a string with the two middle ones. (For example, calling the method with the value "rockbud" should return the string "k", whereas calling it with "crem" should return the value "re".)
  24. A function nuke_last which takes two arguments, a list and an item. The method should modify the passed list in place to remove the last entry matching the element. If the item passed is not in the list, the method should do nothing. (For example, if a variable "droids" has the value [ 'R', 2, 'D', 2, 'C', 3, 'P', 'O' ]", then after calling the method with droids and 2, the variable should have the contents [ 'R', 2, 'D', 'C', 3, 'P', 'O' ]".) The method need return nothing.
  25. A function middlest that takes three (numeric) arguments, and returns the value of the middle one in numerical order. (For example, middlest(5,7,2) should return 5. In case of ties, do what's obvious.)
  26. A function tack_on_end that takes three arguments, the last one optional. Argument #1 is a list. Argument #2 may be either a list or an atomic type (like a string or integer). The function should add either the elements of argument #2, in order (if argument #2 is a list), or argument #2 itself (if argument #2 is anything else) to the end of argument #1. It should do this a number of times equal to the third argument, whose default value should be 1. For example, suppose a variable "bridgemen" has the value
    ['Teft','Moash'].

    If tack_on_end(bridgemen,['Sigzil','Lopen']) is called, bridgemen should then have the value:

    ['Teft','Moash','Sigzil','Lopen'].

    Then, if tack_on_end(bridgemen,'Rock',4]) is called, bridgemen should have the value

    ['Teft','Moash','Sigzil','Lopen','Rock','Rock','Rock','Rock'].

    Finally, if tack_on_end(bridgemen,['Shen','Skar'],2]) is then called, bridgemen should have the value

    ['Teft','Moash','Sigzil','Lopen','Rock','Rock','Rock','Rock','Shen','Skar','Shen','Skar'].

    The function need return nothing.

  27. A function wondrous_count that takes one integer, and returns the number of steps required to reach 1 from that number in a Collatz sequence. The Collatz Conjecture (never yet proven) postulates the following. Take any positive integer. If it is even, divide it in half. If it's odd, triple it and add one. Keep doing this until you get the number 1. The Collatz Conjecture hypothesizes that every number will eventually reach 1 this way. (Examples: wondrous_count(1) should return 0, wondrous_count(3) should return 7, and wondrous_count(16) should return 4.)
  28. A function unique_vals that takes a dictionary and returns a list (in any order) of the unique values of that dictionary. For instance, unique_vals({'Sadeas':'human','Pattern':'spren','Syl':'spren'}) should return the list ['spren','human'] (or ['human','spren']).

Scoring yourself

Any time you want to check your work, rerun "python pythonpractice.py myumwnetid" on the command line. Your new score will show in the display.

Turning it in

To turn in this assignment, send me an email with subject line "DATA/CPSC 350 assignment #0 turnin", and with your myumwnetid_pythonpractice.py file as an attachment, by the deadline.

Getting help

I'm happy to answer questions and give hints! Come to office hours, or send me email with subject line "CPSC/DATA 350 Assignment #0 help!!"