13,420
edits
Changes
→PART 1 - Providing Functions With Arguments
</source>
'''Practice Multiple Levels of IndentationCreate a Python Script with an Advanced Function'''
:'''Perform the Following Instructions:'''
:#Create the '''~/ops435/lab3/lab3c.py''' script. The purpose of the script is to make a single function that can perform addition, subtraction, or multiplication on a pair of numbers. But the function will allow us to choose exatly what operation we are performing on it when we call the function. If the operate function does NOT understand the operator given, it should return a error message.
:::4. Sample Import 1:<source>
import lab3c
lab3c.operate(10, 20, 'add')
30
lab3c.operate(2, 3, 'add')
5
lab3c.operate(100, 5, 'subtract')
95
lab3c.operate(10, 20, 'subtract')
-10
lab3c.operate(5, 5, 'multiply')
25
lab3c.operate(10, 100, 'multiply')
1000
lab3c.operate(100, 5, 'divide')
Error: function operator can be "add", "subtract", or "multiply"
lab3c.operate(100, 5, 'power')
Error: function operator can be "add", "subtract", or "multiply"
</source>