Lesson 19 - Functions in Python: Quiz 4 Review
Lesson 19 - Functions in Python: Quiz 4 Review
Quiz 4 Review
WHILE LOOPS
Class_grades = [ [85,91,89] , [78,81,86], [62,75,77],]
Total = 0
K=0
While k < len(class_grades)
Total = total + class_grades[k][2]
K=k+1
Print(Avg. for Third exam=, total / float(k))
Welcome to Functions
What is a Function?
-
Standalone program
Performs a known task
We might not even know how!
Print, input, len, key, etc.
Term
KLOC
MLOC
GLOC
Equivalent storage
application
Defining Syntax
Function header def avg(n1,n2,n3):
Function Body(suite) ----------------------------A function header starts with the keyword def
Followed by an identifier(avg)
which is the functions name
Function name followed by a comma-separated list of identifiers (n1,n2,n3)
Called formal parameters
Or simply parameters
Even an empty list of parameters, like? Exit, break, print
Then a colon ( : )
Def max(a,b):
If a>b:
Return a
Else:
Return b
Lets RECAP
What a function entails
3 things!
Every Function
1) Performs a known task
2) Known inputs
3) Known return(s) or None