Changes

Jump to: navigation, search

OPS435 Python Lab 3

68 bytes added, 11:37, 3 June 2017
PART 3 - Iterating Over Lists
:#Create the '''~/ops435/lab3/lab3f.py''' script. The purpose of this script is to use functions to modify items inside a list. <source>
#!/usr/bin/env python3
 
# Place my_list below this comment (before the function definitions)
:::*The list '''my_list''' should have the values: '''1, 2, 3, 4, 5'''
:::*The script should have a function called '''add_item_to_list(my_list) ''' :::*The script should have a function called '''remove_items_from_list(my_list, items_to_remove) ''' :::*The function '''add_item_to_list(my_list''') takes a single argument which is a list. This function will look at the value of the last item in the list, it will then append a new value that is '''+1 ''' bigger then the previous number. This function modifies the list without returning any value:::*The function '''remove_items_from_list(my_list, list_of_numbers_to_remove) ''' takes two arguments, a list, and a list of numbers to remove from the list. This function will then check if those items are in the list, if they are it will remove them. This function modifies the list without returning any value. :::2. '''Sample Run 1:'''<source>
run lab3f.py
[1, 2, 3, 4, 5]
[2, 3, 4, 7, 8]
</source>
 :::3. '''Sample Import 1Run 2 (with import):'''<source>
from lab3f import * [1/1899]
 
my_list
[1, 2, 3, 4, 5]
 
add_item_to_list(my_list)
add_item_to_list(my_list)
add_item_to_list(my_list)
 
my_list
[1, 2, 3, 4, 5, 6, 7, 8]
 
remove_items_from_list(my_list, [1,5,6])
 
my_list
[2, 3, 4, 7, 8]
</source>
:::42. Exit the ipython3 shell, download the checking script and check your work. Enter the following commands from the bash shell.<source>
cd ~/ops435/lab3/
pwd #confirm that you are in the right directory
python3 ./CheckLab3.py -f -v lab3f
</source>
:::53. Before proceeding, make certain that you identify any and all errors in lab3f.py. When the checking script tells you everything is OK before proceeding to the next step.
::Make notes for all of your observations in your lab log book, and proceed to INSTRUCTOR SIGN-OFF.
13,420
edits

Navigation menu