






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The f(x) analogy is misleading because Python functions may or may not return a value. • display prints a value and then returns/leaves.
Typology: Schemes and Mind Maps
1 / 12
This page cannot be seen from the preview
Don't miss anything!







Two Types Composition Boolean Functions Math Library
Slide 1 of 12
Go Back
Full Screen
October 8, 2015 Brian A. Malloy
Two Types Composition Boolean Functions Math Library
Slide 2 of 12
Go Back
Full Screen
def display(x): print "x is ", x
def double(x): return 2*x
Two Types Composition Boolean Functions Math Library
Slide 4 of 12
Go Back
Full Screen
1 def display(x): 2 print "x is ", x 3 4 print display(12)
x is 12 None
Two Types Composition Boolean Functions Math Library
Slide 5 of 12
Go Back
Full Screen
1 def badAbs(x): 2 if x > 0: 3 return x 4 elif x < 0: 5 return -x 6 7 print badAbs(12) 8 print badAbs(-12) 9 print badAbs(0)
12 12 None
Two Types Composition Boolean Functions Math Library
Slide 7 of 12
Go Back
Full Screen
Two Types Composition Boolean Functions Math Library
Slide 8 of 12
Go Back
Full Screen
1 def fixedAbs(x): 2 if x < 0: 3 return -x 4 else: 5 return x
6 def display(x): 7 print fixedAbs(x), "is positive"
8 display(12) 9 display(-12) 10 display(0)
Two Types Composition Boolean Functions Math Library
Slide 10 of 12
Go Back
Full Screen
1 def isEven(x): 2 return x % 2 == 0 3 4 print isEven(12) 5 print isEven(17) 6 print isEven(0)
True False True
Two Types Composition Boolean Functions Math Library
Slide 11 of 12
Go Back
Full Screen
https://docs.python.org/2/library/math.html
1 import math 2 3 def areaCircle(radius): 4 return math.pi * (radius**2) 5 6 print math.factorial(5) 7 print math.fabs(-5.3) 8 print math.pi 9 print areaCircle(5) 10 print math.sqrt( math.fabs(-3.0) )