Functions Own
Functions Own
Ibrahim Abou-Faycal
#
EECE-231
#
Introduction to Computation & Programming with Applications
#
Functions - Own Functions
Reading: [Guttag, Sections 4.1,4.2, 4.5, and 5.3] Material in these slides is based on
• Slides of EECE-230C & EECE-230 MSFEA, AUB
• [Guttag, Chapter 4]
• [MIT OpenCourseWare, 6.0001, Lecture 4, Fall 2016]
0.1.1 Syntax
• If the function returns a value, the function body contains a return statement
return value
1
• Otherwise, its body may or may not contain a return statement to stop the execution of the
function
return
• Calling the function:
[ ]: actualParameter1 = 1
actualParameter2 = 3
actualParameter3 = 2
functionName(actualParameter1, actualParameter2, actualParameter3)
Example
[ ]: def maxVal(x,y):
"""
Return the max of x and y
"""
if x > y:
return x
else:
return y