15.7 Exercises
From Foundations of Python ProgrammingGNU FDL 1.3Original pagePython1 class period3 exercises2 graded tests
README.md
15.7 Exercises
Read first in the book: 15.3 Anonymous functions with lambda expressions, 15.4 Programming With Style, 15.5 Method Invocations, 15.6 Function Wrapping and Decorators.
Exercise 1
- Fill in the parameter list for g so that the invocations of g yield the return values specified
Open the
01folder and editmain.py. This one is not graded, so check it yourself.
Exercise 2
- Define a function called
numsthat has three parameters. The first parameter, an integer, should be required. A second parameter namedmult_intshould be optional with a default value of 5. The final parameter,switch, should also be optional with a default value of False. The function should multiply the two integers together, and if switch is True, should change the sign of the product before returning it.
Open the
02folder and editmain.py. Run Tests checks it.
Exercise 3
- Write a function called
togetherthat takes three parameters, the first is a required parameter that is a number (integer or float), the second is a required parameter that is a string, and the third is an optional parameter whose default is " ". What is returned is the first parameter, concatenated with the second, using the third.
Open the
03folder and editmain.py. Run Tests checks it.
For teachers
15.7 Exercises
Students read Foundations of Python Programming's “Exercises” in CS Room and work through its 3 Python coding exercises (2 graded).
- Time: 1 class period
- Tests: 2 in 2 graded exercises, set up for you when you import the lesson
Reading first
- 15.3 Anonymous functions with lambda expressions
- 15.4 Programming With Style
- 15.5 Method Invocations
- 15.6 Function Wrapping and Decorators
Exercises
| Folder | Grading | Tests |
|---|---|---|
01 | Not graded; students check it themselves | 0 |
02 | Autograded | 1 |
03 | Autograded | 1 |