Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 4

17,182 bytes removed, 08:26, 21 January 2020
no edit summary
<font color='red'>
'''** DO NOT USE - TO BE UPDATED FOR CENTOS 8.0 **'''
</font>
= OBJECTIVES =
=== 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.
::*The script should contain no errors
:::'''Sample Run 1:'''<source>
run ./lab4b.py
list1: [1, 2, 3, 4, 5, 6, 7, 8, 9]
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>
</source>
:::*The script should contain '''threetwo''' functions::::::'''create_dictionary()'''<ol><li>'''accepts''' two lists as arguments keys and values, '''combines''' these lists together to '''create''' a dictionary</li><li>'''returns a dictionary''' that has the keys and associated values from the lists<br>('''Tip:''' use a while loop to access elements in both the keys and values lists at the same time)</li><li>'''returns a dictionary''' that has the keys and associated values from the lists</li></ol>
:::::'''shared_values()''' <ol><li>'''accepts''' two dictionaries as arguments and '''finds''' all values that are shared between the two dictionaries<br>('''Tip:''' generate sets containing only values for each dictionary, then use a function mentioned in a previous section to store the values that are common to <u>both</u> lists)</li><li>'''returns a set''' containing '''ONLY values''' found in '''BOTH dictionaries'''</li></ol>
:::*make sure the functions have the correct number of arguments required
:::*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)
= INVESTIGATION 2: STRINGS =
:Strings are basically a list of characters (bits of text). Strings store text so that they can be later for manipulation (by a wide range of functions). This section will investigate strings in more detail such as '''cutting strings into sub-strings''', '''joining strings''', '''formatting strings''', '''searching through strings''', and '''matching strings against patterns'''.<br><br>Strings are '''immutable''' data objects - this means that once a string is created, it <u>cannot</u> be modified. In order to make a change inside a string, you would first make a copy of the part of the string (i.e. sub-string) for manipulation.
== PART 1 - Strings and Substrings ==
:'''Perform the Following Steps:'''
:#Launch the ipython3 shell<source>ipython3</source>:#Issue the following to create Create some stringsin a temporary Python file:<sourcelang="python">
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'''. In our ipython3 shell the values inside each string variable can be seen just by typing the string variable name. However, when writing python scripts, these string variables should be placed inside '''print()''' functions in order to display on the screen.<br><br> :#Strings can also be '''concatenated''' (i.e. "combined together") by using the '''+''' sign, just make sure string are only concatenating other strings with strings(no lists, no numbers, no dictionaries, etc.).<br><br>:#To demonstrate what was previously mentioned, issue the following:<sourcelang="python">course_namecourse_codecourse_number
print(course_name)
print(course_code)
print(str(course_number))
print(course_name + ' ' + course_code + ' ' + str(course_number))
</source>Strings can also use special syntax for string '''repetition''' by <u>multiplying</u> the string by a number. This will repeat that string that many times. Repetition with '''*''' is useful whenever a string needs to be repeated more than once<br><br>:#Issue the following:<source>print(course_name + '-' + course_code)print(course_name + '-'*5 + course_code)print(course_name + '-'*25 + course_code)print('abc'*2)print(course_code*5)</source>When using the '''print()''' function, you can display '''special characters'''. One such special character is the is the newline character (denoted by the symbol: '''\n'''). This allows you to separate content between new lines or empty lines.<br><br>:#To demonstrate, issue the following:<sourcelang="python">
print('Line 1\nLine 2\nLine 3\n')
</source>
:#By using both Strings have many built-in functions that we can use to manipulate text. [https://docs.python.org/3/library/stdtypes.html#string repetition and -methods Here's a newline character, multiple lines can be created at oncelist]. Issue the following:#Lets try out several different functions:<sourcelang="python">print('Line 1' + '\n'*4 + 'Line 5\nLine 6'course_name.lower()) # Returns a string in lower-case lettersprint(course_name.upper()) # Returns a string in upper-case lettersprint(course_name.swapcase()) # Returns a string with upper-case and lower-case letters swappedprint(course_name.title()) # Returns a string with upper-case first letter of each word, lowercase for remaining textprint(course_name.capitalize()) # Returns a string with upper-case first letter only, lowercase for remaining text
</source>
:#Strings have many built-in functions that we can use to manipulate text. Let's take a look at the strings name space and the available functions:<source>dir(course_name)help(course_name)</source>:#Lets try out several different functions. Refer back to the '''help()''' function for more information, these are quick ways to view strings in different ways. Issue the following:<source>course_name.lower() # Returns a string in lower-case letterscourse_name.upper() # Returns a string in upper-case letterscourse_name.swapcase() # Returns a string with upper-case and lower-case letters swappedcourse_name.title() # Returns a string with upper-case first letter of each word, lowercase for remaining textcourse_name.capitalize() # Returns a string with upper-case first letter only, lowercase for remaining text</source>:#These values can be saved inside new strings and then reused:<sourcelang="python">
lower_name = course_name.lower() # Save returned string lower-case string inside new string variable
print(lower_name)
lower_name.split(' ') # Provide the split() function with a character to split on
</source>The above example will return a list of strings, which we can access just like all of lists. <br><br>
:#Let's practice more string manipulation by issuing the following:<sourcelang="python">
list_of_strings = lower_name.split(' ') # Split string on spaces and store the list in a variable
print(list_of_strings ) # Display listprint(list_of_strings[0] ) # Display first item in list</source>Since lists are actually a list of '''strings''', you should be able to use any function that works with a string on a list.<br><br>:#To demonstrate, issue the following:<sourcelang="python">
list_of_strings[0].upper() # Use the function after the index to affect a single string within a list
first_word = list_of_strings[0]
first_word
print(first_word)
</source>The '''index''' that is used to access <u>items</u> within a list, can also be used to access <u>characters</u> within a string. For practice, let's create a new string, and start accessing the strings index.<br><br>:#Issue the following:<source>
course_name = 'Open System Automation'
course_code = 'OPS435'
course_number = 435
print(course_code[0] ) # Return a string that is Print the first character in course_codeprint(course_code[2] ) # Return a string that is Print the third character in course_codeprint(course_code[-1] ) # Return a string that is Print the last character in course_codeprint(str(course_number)[0] ) # Turn the integer into a string, return first character in that string, and print itprint(course_code[0] + course_code[1] + course_code[2])</source>:#You can use a technique that uses index numbers of a string to '''cut-out''' or '''"parse"''' smaller portions of text within a string. This term is referred to as a '''substring'''. We can use this to create a new string or display only a small portion of it<br><br>:#To demonstrate, issue the following:<sourcelang="python">print(course_name[0:4] ) # Return Print the first four characters (values of index numbers 0,1,2, and 3)
first_word = course_name[0:4] # Save this substring for later use
print(course_code[0:3] ) # Return Print the first three characters (values of index numbers 0,1,and 2)
</source>
:# The index allows a few '''extra functions''' using the same parsing technique:<sourcelang="python">
course_name = 'Open System Automation'
print(course_name[12:] ) # Return Print the substring '12' index until end of stringprint(course_name[5:] ) # Return Print the substring '5' index until end of stringprint(course_name[-1] ) # Return Print the last character</source>With '''negative indexesindices''', '''-1''' index would represent the '''last''' character, '''-2''' index would represent the '''second last''' character, etc.<br><br>:#To demonstrate, issue the following:<sourcelang="python">
course_name = 'Open System Automation'
print(course_name[-1])print(course_name[-2])
</source>
:# Issue the following to practice Practice some of the skills that you have learned in this section:<source>
course_name = 'Open System Automation'
print(course_name[-10:] ) # Return the last ten charactersprint(course_name[-10:-6] ) # Try and figure out what this is returning print(course_name[0:4] + course_name[-10:-6] ) # Combine substrings together
substring = course_name[0:4] + course_name[-10:-6] # Save the combined substring as a new string for later
print(substring)
</source>
:# The real power found in substrings goes beyond just manually writing index values and getting back words. The next part of this investigation will cover how to search through a string for a specific word, letter, number, and return the index to that search result.
'''Create a Python Script Demostrating Substrings'''
:'''Perform the Following Instructions'''
::#Create the '''~/ops435/lab4/lab4d.py''' script. The purpose of this script is to demonstrate creating and manipulating strings. There will be four functions each will return a single string.::#Use the following template to get started:<source>
#!/usr/bin/env python3
# Strings 1
</source>
:::*The script should contain '''four''' functions (use your own argument names)::::::'''first_five()''':<ol><li>Accepts a single string argument</li><li>Returns a string that contains the first five characters of the argument given</li></ol>:::::'''last_seven()''':<ol><li>Accepts a single string argument</li><li>Returns a string that contains the last seven characters of the argument given</li></ol>:::::'''middle_number()''':<ol><li>Accepts a integer as a argument</li><li>Returns a string containing the second and third characters in the number</li></ol>:::::'''first_three_last_three()''':<ol><li>Accepts two string arguments</li><li>Returns a single string that starts with the first three characters of argument1 and ends with the last three characters of argument2</li></ol>:::*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. Exit the ipython3 shell, download 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>
:::4. Before proceeding, make certain that you identify any and all errors in lab4d.py. When the checking script tells you everything is OK before proceeding to the next step. <!-- REMOVING PART 2 and PART 3 of string formatting. MOVED TO EXTRAS: https://wiki.cdot.senecacollege.ca/wiki/OPS435_Python_Extra_Advanced_String_formatting == PART 2 - String Formatting Basic Fundamentals== :In Python scripting, using plus signs and commas for string concatenation is very limited and can become messy when when used at length with many values and/or calculations. This section will cover the '''format()''' function that can be used with every type of string. This function allows the user of Python to create well formatted code, to align text, and to convert values efficiently and cleanly. While this section uses lists and dictionaries, they contain strings which can be accessed and displayed in a formatted manner. :'''Perform the Following Steps:''':#Start the ipython3 shell:<source>ipython3</source>To start, let's use the '''format()''' function on a string, The text '''.format()''' is located at the end of a defined string. The ''format()'' function can contain arguments or parameters within the parenthesis ( ).<br><br>:#To demonstrate using the ''format()'' function, issue the following:<source>print( 'College is Great'.format() )</source>:#The above example does not actualy do any formatting, next add a string using the format() function arguments<source>print('College is {}'.format('Great'))</source>When the format function reads '''{}''' curly braces, it performs special actions. For example, if format() finds '''{}''' with nothing inside it substitutes the string from it's arguments. These arguments are done by position left to right<br><br>:#To demonstrate, issue the following:<source>print('{} {} {}'.format('a', 'b', 'c'))</source>However, using this method while quick, easy, and clean has a issue. If more curly braces '''{}''' are in the string than in the format() arguments, it will create an '''error'''.<br><br>:#To demonstrate by creating too many braces, issue the following:<source>print('{} {} {} {}'.format('a', 'b', 'c'))</source>For situations like above, if reusing strings more than once is important, '''positional values''' can be placed inside the curly braces.<br><br>:#Issue the following to see what happens:<source>print('{0} {1} {1} {2}'.format('a', 'b', 'c'))print('{2} {2} {1} {0}'.format('a', 'b', 'c'))</source>These positions make formating each string much less prone to errors while also making the string being formatted much more clear.<br><br>:#To improve on formatting further, issue the following to provide the format() function with string variables:<source>course_name = 'Open System Automation'course_code = 'OPS435'print('{0} {1} {0}'.format(course_code, course_name))</source>The format() function by default tries to use values as strings, all values is '''{}''' are displayed as strings unless extra options are given.<br><br>:#Issue the following:<source>course_number = 435 # This is an integerprint('This is displaying a string by default: {0}'.format(course_number))</source>Next, let's place a list inside the format() function and access the values, there are two ways to use the list.<br><br>:#Let's demonstrate a range of alternative methods of printing a list by issuing the following:<source>list1 = [1,2,3,4,5] # This is a list of numbersprint('{0[0]} {0[1]} {0[2]} {0[3]} {0[4]}'.format(list1)) # Access the values of the list via {position[index]} print('{0} {1} {2} {3} {4}'.format(*list1)) # Expand the list into multiple positional argumentsprint('{} {} {} {} {}'.format(*list1)) # Expand the list into multiple positional argumentsprint('{0} {1} {2} {3} {4}'.format(1,2,3,4,5)) # Same results as above</source>Let's now place a dictionary inside the format() functions and access the values, again there are a few ways to use the dictionary<br><br>:#Issue the following:<source>dict_york = {'Address': '70 The Pond Rd', 'City': 'Toronto', 'Country': 'Canada', 'Postal Code': 'M3J3M6', 'Province': 'ON'}print('{}'.format(dict_york)) # Print entire dictionaryprint('{0}'.format(dict_york)) # Print entire dictionary using format arguments positionprint('{0[City]} {0[Country]}'.format(dict_york)) # Print values using position and key {position[key]}</source>With dictionaries however, instead of using positional arguments '''0''' each access to a key, python allows for expansion of keyword arguments.<br><br>:#Let's take a look at the example of a keyword arguments, place the keyword variable name in between '''{}''' and add the keyword argument to the format() function:<source>print('{string1} is {string2} {string2}'.format(string1='College', string2='Great!'))</source>:#Variables may also be passed to these keyword arguments:<source>college = 'Seneca College'print('{string1} is {string2} {string2}'.format(string1=college, string2='Great!'))</source>Now back to dictionaries. Using keyword arguments(sometimes referred to as '''kwargs''' in python). The dictionary can be quickly and easily expanded into these keyword arguments using the syntax '''**dictionary_name'''.<br><br>:#Let's try this below. Pay close attention to the keys inside the dictionary and the values associated with each key:<source># Define a dictionary:dict_york = {'Address': '70 The Pond Rd', 'City': 'Toronto', 'Country': 'Canada', 'Postal Code': 'M3J3M6', 'Province': 'ON'}# Uses the dictionary's keyword arguments:print('{City} {Province} {Country}'.format(**dict_york)) # Creates new keyword arguments:print('{City} {Province} {Country}'.format(City='Toronto', Province='ON', Country='Canada')) </source> == PART 3 - String Formatting Advanced Features == This section shows you how to perform more advanced formatting features via the '''format()''' function. You will learn how to format numbers and aligning strings (text). :'''Perform the Following Steps''':#Make certain you are still in your ipython3 shell.<br><br>Let's start advanced formatting for '''numbers'''. Try issuing content below in order to observe the various ways to change the output inside the curly brace '''{}''' while formatting. This formatting change is done by placing a colon inside the curly braces, following by a letter '''{0:f}'''<br><br>:#Issue the following:<source>number1 = 50 number2 = -50number3 = 1.50print('{0:f}'.format(number1)) # "0" is the position just like other format() functionsprint('{0:f}'.format(number2)) # A colon separate the position/index areas from the extra functionalityprint('{0:f}'.format(number3)) # "f" represents the fixed point number</source>Notice that there are many decimal places after this number. This makes the number look "ugly". We need to further format the number to indicate the number of decimal places (or no decimal places if number is an integer). A fixed point number means that it can control the number of digits that come after the decimal point, try changing the '''.2''' to any other number and experiment.<br><br>:#Issue the following to demonstrate:<source>print('{0:.0f}'.format(number1)) # Show no digits after decimal pointprint('{0:.2f}'.format(number2)) # Show two digits after decimal pointprint('{0:.1f}'.format(number3)) # Show one digit after decimal point</source>:#Numbers can be displayed with the '''-''' or '''+''' signs before the digits, this could be important in formatting. Issue the following to demonstrate:<source>print('{0: f}'.format(number1)) # Show a space where plus sign should beprint('{0: f}'.format(number2)) # Shows negative sign normallyprint('{0: f}\n{1: f}'.format(number1, number2)) # The space before the f lines up positive and negative numbers</source>:#Placing a '''+''' before the f changes the format so that plus signs show up for positive numbers and negative signs show up for negative numbers. Try issuing the following:<source>print('{0:+f}'.format(number1)) # Show a space where plus sign should beprint('{0:+f}'.format(number2)) # Shows negative sign normallyprint('{0:+f}\n{1:+f}'.format(number1, number2)) # The space before the f lines up positive and negative numbers</source>:#Combining fixed point positions can be performed by issuing the following:<source>print('{0:+.2f}'.format(number1))print('{0:+.2f}'.format(number2))print('{0:+.2f}\n{1:+.2f}'.format(number1, number2))</source>In the event that the numbers being shown are all integers and do no require the decimal values, instead of using '''{:f}''',<br> use '''{:d}''' for decimal '''integers'''.<br><br>:#To demonstrate, issue the following:<source>print('{0:d}'.format(number1))print('{0:d}'.format(number2))print('{0: d}'.format(number1))print('{0: d}'.format(number2))print('{0:+d}'.format(number1))print('{0:+d}'.format(number2))</source>'''NOTE:''' When using '''{:d}''' be careful not to use numbers with a decimal value in them, the following will create a error<br><br>:#Issue the following to see the difference:<source>number3 = 1.50print('{0:d}'.format(number3))</source>Next, let's move on to aligning '''strings''' (text). This is the process of adding padding to the left of our text, the right of our text, or aligning to the centre or our text (i.e. padding both left and right). Through the alignment the text field size, any string can be set to allow it to fit within a column (or columns), and make it easier for the user to read data.<br><br>:#Start by using a string but placeing a number value after the colon '''{0:10}''' by issuing:<source>string1 = 'hello'string2 = 'world'print('{0:10}{1}'.format(string1, string2)) # Make sure string1 is 10 characters aligned to the leftprint('{0:6}{1}'.format(string1, string2)) # Make sure string1 is 6 characters aligned to the left</source>By default, the format() function aligns to the left, the symbol to do this is '''<''' which is a shortcut for : '''{0:<10}''' when used in the curely braces. Now whenever a different string is placed inside it always aligns to the left 10 characters. This allows for concise code to generate well structured output<br><br>:#To demonstrate this, issue the following:<source># Without positional argument numbersprint('{:<10} {:<10} {:<10}\n{:<10} {:<10} {:<10}'.format('abc', 'def', 'ghi', 'jkl123', 'mno123', 'pqr123'))# With positional argument numbersprint('{0:<10} {1:<10} {2:<10}\n{3:<10} {4:<10} {5:<10}'.format('abc', 'def', 'ghi', 'jkl123', 'mno123', 'pqr123')) </source>:#Next try using right alignment with the '''>''' symbol replacing the left alignment<source># Without positional argument numbersprint('{:>10} {:>10} {:>10}\n{:>10} {:>10} {:>10}'.format('abc', 'def', 'ghi', 'jkl123', 'mno123', 'pqr123'))# With positional argument numbersprint('{0:>10} {1:>10} {2:>10}\n{3:>10} {4:>10} {5:>10}'.format('abc', 'def', 'ghi', 'jkl123', 'mno123', 'pqr123')) </source>:#Finally, you can centre the alignment of strings using the '''^''' symbol. Issue the following:<source># Without positional argument numbersprint('{:^10} {:^10} {:^10}\n{:^10} {:^10} {:^10}'.format('abc', 'def', 'ghi', 'jkl123', 'mno123', 'pqr123'))# With positional argument numbersprint('{0:^10} {1:^10} {2:^10}\n{3:^10} {4:^10} {5:^10}'.format('abc', 'def', 'ghi', 'jkl123', 'mno123', 'pqr123'))</source>The alignment character can be changed to any other character that is wanted for the output. By default it's a space, but it could be anything else by adding an additional character '''{:M<10}''' such as '''M''' or '''*''' before the alignment character<br><br>:#To see this, issue the following:<source>print('{:*^10} {:*^10} {:*^10}\n{:*^10} {:*^10} {:*^10}'.format('abc', 'def', 'ghi', 'jkl123', 'mno123', 'pqr123')) # Without positional argument numbersprint('{:.^10} {:.^10} {:.^10}\n{:.^10} {:.^10} {:.^10}'.format('abc', 'def', 'ghi', 'jkl123', 'mno123', 'pqr123')) # Without positional argument numbers</source>You can make the output appear better by creating borders. Below is a function in order to create a border containing data. If you learned MySQL, you may have seen borders used to display table data, etc. Try defining and running the user-defined function below to see what happens.<br><br>:#Issue the following:<source># Define the function "print_with_borders()":def print_with_borders(): print('|{:-^10}|'.format('nums')) print('|{:^5}{:^5}|'.format(1,2)) print('|{:^5}{:^5}|'.format(3,4)) print('|{}|'.format('-'*10)) # Run the function "print_with_borders()":print_with_borders()</source>'''Create a Script Demonstrating Formatting Strings''':'''Perform the Following Instructions:'''::#Create the '''~/ops435/lab4/lab4e.py''' script. The purpose of this script is to demonstrate formatting string output from a large data structure.::#Use the following template to get started:<source>#!/usr/bin/env python3# Formatted Strings dict_york = {'Address': '70 The Pond Rd', 'City': 'Toronto', 'Country': 'Canada', 'Postal Code': 'M3J3M6', 'Province': 'ON'}college = 'Seneca College' def print_college_address(): # Prints out the keys and values from the dictionary # Formats the output to have a title bar with a title # EXACT SAME output as the samples if __name__ == '__main__': print_college_address(dict_york, college) </source>:::*The '''print_college_address()''' function does NOT return anything:::*The '''print_college_address()''' function accept two arguments:::*The first argument is a '''dictionary''':::*The second argument is a '''string''':::*The title printed is '''center''' aligned by '''40 characters''' using '-' instead of space for alignment:::*The keys printed are '''center''' aligned by '''20 characters''':::*The values printed are '''center''' aligned by '''20 characters''':::*The output must match the sample output EXACTLY if one character is off it will be wrong:::'''Sample Run 1:'''<source>run lab4e.py|-------------Seneca College-------------|| Address 70 The Pond Rd || Province ON || Postal Code M3J3M6 || City Toronto || Country Canada ||----------------------------------------|</source>:::'''Sample Run 2(with import):'''<source>import lab4edict_york = {'Address': '70 The Pond Rd', 'City': 'Toronto', 'Country': 'Canada', 'Postal Code': 'M3J3M6', 'Province': 'ON'}dict_newnham = {'Address': '1750 Finch Ave E', 'City': 'Toronto', 'Country': 'Canada', 'Postal Code': 'M2J2X5', 'Province': 'ON'}college = 'Seneca College' lab4e.print_college_address(dict_york, college)|-------------Seneca College-------------|| Address 70 The Pond Rd || Province ON || Postal Code M3J3M6 || City Toronto || Country Canada ||----------------------------------------| lab4e.print_college_address(dict_newnham, college)|-------------Seneca College-------------|| Address 1750 Finch Ave E || Province ON || Postal Code M2J2X5 || City Toronto || Country Canada ||----------------------------------------|</source>::3. Exit the ipython3 shell, 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 directoryls CheckLab4.py || wget matrix.senecac.on.ca/~acoatley-willis/CheckLab4.pypython3 ./CheckLab4.py -f -v lab4e</source>::4. Before proceeding, make certain that you identify any and all errors in lab4e.py. When the checking script tells you everything is OK before proceeding proceed to the next step.<br><br>-->
= LAB 4 SIGN-OFF (SHOW INSTRUCTOR) =
1,760
edits