Ex4 - Introduction to Lists:

Objective: Learn what lists are and how to start working with the elements in a list.

Description: Record three courses you are currently enrolled into a Python list. Add to the Python list additional courses you plan to register for next semester. Print the courses to the terminal.

  • Note: To complete this exercise, please follow the instructions on the Getting Started > Tools > uv Package Manager page to set up and run your script with uv.

  1. In your project folder, Ex4, initialize a uv project by running uv init --no-package in the terminal (only needs to be done once per folder). For this exercise, you’ll run your Python file with uv run filename.py.
  2. Rename the exercise file: Ex4_Lists.py.
  3. Write a script that will allow you to record three courses you are enrolled in (e.g., CIS240). To do so, first initialize an empty Python list defined as courses = []. Then, use the input() function to add each course to the Python list.
  4. Next, using the append() method, record each course to the Python list and print the list to the terminal.
  5. Expand on the program to include two additional courses you plan to register for next semester.
    • Use insert() to add one new course you plan to register for next semester to the beginning of your list.
    • Use append() to add the other new course you plan to register for next semester to the end of your list.
  6. Finally, by accessing the courses in the list, print one new line at the end of the file stating that you’re planning to register for these two new courses next semester.
    • In the print statement, do not explicitly write the name of the course, but rather use the syntax to access each course in the list.
  7. Run your script using uv run Ex4_Lists.py.
  • Solution Output Example:

Record the name of your first course: CIS240
Record the name of your second course: CIS251
Record the name of your third course: CIS235
[‘CIS240’, ‘CIS251’, ‘CIS235’]

Next semester I’m planning to register for CIS340 and CIS335