Changes

Jump to: navigation, search

OPS435 Python Lab 4

269 bytes added, 16:39, 5 June 2019
Create a Python Script Demonstrating Comparing Lists
=== PYTHON REFERENCE ===
:As you develop your Python scripting skills, you may start to be "overwhelmed" with the volume of information that you have absorbed over these labs. One way to help, is to learn to use online references effectively in order to obtain information regarding Python scripting techniques and tools.
:Below is a table with links to useful online Python reference sites (by category). You may find these references useful when performing assignments, etc.
list2: [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
join: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
match: [8, 9, 5, 6, 7, 8, 9]
diff: [1, 2, 3, 4, 10, 11, 12, 13, 14]
</source>
:::'''Sample Run 2 (with import)under interactive python shell:'''<source>
import lab4b
list1 = [1,2,3,4,5]
list2 = [2,1,0,-1,-2]
print(lab4b.join_lists(list1,list2)))
# Will output [0, 1, 2, 3, 4, 5, -2, -1]
print(lab4b.match_lists(list1,list2))
# Will output [1, 2]
print(lab4b.diff_lists(list1,list2))
# Will output [0, 3, 4, 5, -2, -1]
</source>
for key in list_of_keys:
print(key)
for value in dict_york.values():
print(value)
</source>
:::*The script should contain no errors
::::'''Sample Run 1:'''<source>
run ./lab4c.py
York: {'Country': 'Canada', 'Postal Code': 'M3J3M6', 'Address': '70 The Pond Rd', 'Province': 'ON', 'City': 'Toronto'}
Shared Values {'Canada', 'ON', 'Toronto'}
list_values = ['70 The Pond Rd', 'Toronto', 'Canada', 'M3J3M6', 'ON']
york = lab4c.create_dictionary(list_keys, list_values)
print(york)
'Province': 'ON'}
common = lab4c.shared_values(dict_york, dict_newnham)
print(common)
course_name = 'Open System Automation'
course_code = 'OPS435'
course_number = '435'
</source>Strings can contain any '''characters''' inside them, whether they are '''letters''', '''numbers''', or '''symbols'''.
:#Strings can also be '''concatenated''' (i.e. "combined together") by using the '''+''' sign, just make sure string are only concatenating strings with strings (no lists, no numbers, no dictionaries, etc.):<source lang="python">
::*Example: first_three_last_three('abcdefg', '1234567') returns single string 'abc567'
:::'''Sample Run 1'''<source>
run ./lab4d.py
Hello
Senec
Send!!
</source>
:::'''Sample Run 2(with import)'''<source>
import lab4d
 
str1 = 'Hello World!!'
str2 = 'Seneca College'
num1 = 1500
num2 = 1.50
 print(lab4d.first_five(str1))# Will output 'Hello'print(lab4d.first_five(str2))# Will output 'Senec'print(lab4d.last_seven(str1))# Will output 'World!!'print(lab4d.last_seven(str2))# Will output 'College'print(lab4d.middle_number(num1))# Will output '50'print(lab4d.middle_number(num2))# Will output '.5'print(lab4d.first_three_last_three(str1, str2))# Will output 'Helege'print(lab4d.first_three_last_three(str2, str1))# Will output 'Send!!'
</source>
::3. Download the checking script and check your work. Enter the following commands from the bash shell.<source>
cd ~/ops435/lab4/
pwd #confirm that you are in the right directory
ls CheckLab4.py || wget matrix.senecachttps://raw.ongithubusercontent.cacom/~acoatleySeneca-willisCDOT/ops435/master/LabCheckScripts/CheckLab4.py
python3 ./CheckLab4.py -f -v lab4d
</source>

Navigation menu