Computer Science 112
The Art & Science of Computer Graphics
Spring 2016, The College of Saint Rose
Lecture 22: Python Functions
Date: Monday, April 18, 2016
Agenda
- Announcements
- Python functions
Lecture 22 Assignment
Due at the start of class, Wednesday, April 20.
Please submit answers to these questions
either as a hard copy (typeset or handwritten are OK) or by email to
terescoj AT strose.edu by the start of class. Please use a clear subject line
when submitting by email (e.g., CSC 112 Lecture
22 Assignment, Mary Smith). We will discuss these
questions at the start of class, so no late submissions are
accepted.
Some of these revisit questions from the previous lecture assignment,
now working with Python functions. Just do your best on these. The
topic is new and you haven't had a chance to practice much yet.
- Turn the Python statements that create a "plastic" material
whose color is a randomly chosen shade of gray into a function named
randomGrayPlastic that returns such a material. (5 points)
- Place the Python loop that prints out 5 random numbers in the
range 1 through 6 into a Python function called yahtzeeRoll
that prints out the 5 values, but also returns their sum. (5
points)
- Write a Python function that takes one parameter: a number,
let's call it n, and then uses a loop to generates n random
integers in the range 0-100 and returns their sum. (5 points)
- Write a function lighterHSV, similar in format to the
lighterRGB function, that returns a lighter shade of a given
HSV color. (5 points)
Terminology
- functions
- suite
- function body
- tuple
Examples
- On the Wiki: BaaBaaBad, Downloadable file: BaaBaaBad.py
- On the Wiki: BaaBaaBetter, Downloadable file: BaaBaaBetter.py
- On the Wiki: BaaBaa2Functions, Downloadable file: BaaBaa2Functions.py
- On the Wiki: CountDownFrom10, Downloadable file: CountDownFrom10.py
- On the Wiki: CountDown, Downloadable file: CountDown.py
- On the Wiki: NumberInfo, Downloadable file: NumberInfo.py
- On the Wiki: Sum1ToN, Downloadable file: Sum1ToN.py
- On the Wiki: Sum1ToNBetter, Downloadable file: Sum1ToNBetter.py
- On the Wiki: PlasterMat, Downloadable file: PlasterMat.py
- On the Wiki: PlasticHue, Downloadable file: PlasticHue.py
- On the Wiki: LighterDarkerRGB, Downloadable file: LighterDarkerRGB.py