Computer Science 15-112, Spring 2012
Class Notes: Getting Started with Writing Functions
Writing Functions
def minSquared(x,y):
smaller = min(x,y)
return smaller*smaller
print minSquared(3,4)
print minSquared(4,3)
Another example:
def isEvenPositive(x):
isEven = ((x % 2) == 0)
isPositive = (x > 0)
return (isEven and isPositive)
print(isEvenPositive(-2))
print(isEvenPositive(-1))
print(isEvenPositive(0))
print(isEvenPositive(1))
print(isEvenPositive(2))
carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem