Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

321 bytes added, 11:03, 31 May 2017
PART 2 - Providing Functions With Arguments
== PART 2 - Providing Functions With Arguments ==
:Functions can take arguments that can be passed up to that function for processing. You will be learning how to use arguments with function calls and how useful they can be for tasks such as mathematical processor or testing conditions (eg. error-checking).
:'''Perform the Following Steps:'''
'''Practice Creating Functions With Return Values'''
 
It is time to practice creating a shell script that uses functions that accepts values as arguments that are then used by the functions for processing, and returns a value.
 
:'''Perform the Following Instructions:'''
:#Create a new script '''~/ops435/lab3/lab3b.py'''
The next script is NOT COMPLETE, your job is to make the script do what it askes. It contains 3 functions, one of adding, one for subtracting, and one for multiplying. Make sure each function performs the correct operation and returns a integer value. with the following contents:<source>
def sum_numbers(number1, number2):
# Make this function add number1 and number2 and return the value
def subtract_numbers():
# Make this function subtract number1 and number2 and return the value # Remember to make sure the function accepts 2 arguments
def multiply_numbers():
print(multiply_numbers(10, 5))
</source>
 
:#Create a new script '''~/ops435/lab3/lab3b.py'''
 
:::*The script should have a '''Shebang line'''
:::*The script should have a function sum_numbers(number1, number2)::::: Make this function add number1 and number2 and return the value:::*The script should have a function subtract_numbers(number1, number2)::::: Make this function subtract number1 and number2 and return the value:::: Remember to make sure the function accepts 2 arguments:::*The script should have a function multiply_numbers(number1, number2)::::: Make this function multiply number1 and number2 and return the value:::: Remember to make sure the function accepts 2 arguments
:::*All functions should accept two arguments
:::*All functions should return a an integer
:::*The script should contain no errors
:::2. Sample Run 1:<source>
13,420
edits