Starter File

Refer to the previous lab for instructions on how to open and use a shell application (terminal for Mac/Linux users and the CMD command prompt for Windows users). Once you have a shell up and running, cd into your documents directory and use mkdir PythonLab2 to create a new directory called PythonLab2. Use cd PythonLab2 to enter the directory. Save this file as lab2.py to the PythonLab2 directory. lab2.py contains the function signatures to get you started. Save this file as autograder.py to the PythonLab2 directory as well.

You can test your functions as you go by running python3 autograder.py lab2.py exercise_# in the PythonLab2 directory.

For example: python3 autograder.py lab2.py 3.1 tests exercise 3.1. Use all instead of an exercise number to test all of the functions.

Exercise 1: Push First Odd Back

Fill out the function push_first_odd_back under exercise 1 in the starter file. This function should place the first odd number at the back of the input list. Do not return a new list - in fact this function shouldn't return anything, it should only modify the input list (remember when we talked about mutability a few pages back?). Hint: Just because the previous page was all about the for keyword doesn't necessarily mean that this is the right approach for this problem. Don't forget about while.


>>> lst = [10, 2, 4, 7, 6, 7, 8, 9]
>>> push_first_odd_back(lst)
>>> lst
[10, 2, 4, 6, 7, 8, 9, 7]
        

To test this function, run:


python3 autograder.py lab2.py 1