- p. 60, problem 4
Function declaration: def isLeap(year):
Return values: True or False
>>> isLeap(1500)
False
>>> isLeap(1504)
True
>>> isLeap(1600)
True
>>> isLeap(1601)
False
- p. 60, problem 8
Function declaration: def comb(n, m):
Return values: Integers
>>> comb(3,2)
3
>>> comb(4,2)
6
>>> comb(4,3)
4
>>> comb(5,2)
10
>>> comb(20,10)
184756
- p. 60, problem 9
Function declaration: def power(a,n):
Return values: Integers; a n
- Your solution may not contain the exponentiation operator (
**); if it does, it will get no credit
- Your solution must use recursion as described in the problem statement.
- p. 60, problem 12
Function declaration: def fact(n):
Return values: Integers; n!
>>> fact(4)
24
>>> fact(8)
40320
>>> fact(20)
2432902008176640000
- p. 60, problem 13
You need not write any print statements; just write the function.
The function's parameter indicates the number of terms to generate; ignore
the book's directive to generate exactly ten terms. See how it compares to
math.e for 5, 10, and 20 terms.
Function declaration: def e(n):
Return values: Floating point approximations to e.
>>> e(1)
1.0
>>> e(2)
2.0
>>> e(3)
2.5
- Write a function called
depunctuate(). It will take a
string as an argument, and return a version of that string stripped of
all punctuation and spaces. (This problem is not in the textbook.)
Function declaration: def depunctuate(s):
Return values: Strings without punctuation or spaces
>>> depunctuate("Hello, there!")
'Hellothere'
>>> depunctuate("To be or not to be, that is the question.")
'Tobeornottobethatisthequestion'
>>> depunctuate("word")
'word'
- p. 61, problems 17 and 18.
Function declaration (problem 17): def palindrome17(s):
Function declaration (problem 18): def palindrome18(s):
Return values: True or False
Additional problems
- p. 59: 1,2
- p. 60: 7, 10, 11
- p. 61: 14, 15, 16