Changes

Jump to: navigation, search

OPS435 Python Lab 3

271 bytes removed, 12:01, 10 August 2017
PART 1 - Providing Functions With Arguments
def square(number):
return number ** 2
</source>'''FYI:'''You may have learned that you multiple a number by itself in order to "square" the number. In many computing languagespython, this can be performed by the mathematical expression: '''number ** 2'''.<br><br>In this case, your function takes one argument ('''number'''), and the function operator will perform raise the mathematical operation. You should notice that operand on the square of the number sent up left to the function, and power of the result is returned to the main program (in our case, operand on the ipython3 shell)right.<br><br>When calling functions that contain with multiple arguments to be passed, multiple the arguments are separated by '''commas'''. Be careful NOT to See what happens if you provide strings (, strings without using quotes) , or using numbers that use with decimals in these the following examples, as you may cause errors.
:#Issue the following to test your '''square()''' function:<source>
square(5)
square(square(2))
square('2')
</source>The last function call should produce an '''error message'''. This is caused by sending a '''string''' instead of a number that is processed by the function. By using We could use the int() function, to convert any value passed up by in as a string by mistake will be converted to an integer number.<br><br>
:#Issue the following to declare the function '''sum_numbers()''':<source>
def sum_numbers(number1, number2):
cd ~/ops435/lab3/
pwd #confirm that you are in the right directory
ls CheckLab3.py || wget matrix.senecachttps://raw.ongithubusercontent.cacom/~acoatleySeneca-willisCDOT/ops435/master/LabCheckScripts/CheckLab3.py
python3 ./CheckLab3.py -f -v lab3b
</source>

Navigation menu