Fall 2015, The College of Saint Rose

Lecture 21: Functions
Date: Friday, November 13, 2015

Agenda

• Announcements
• Studio/Lab 8: Stained Glass Windows get any updated submissions in very soon
• Studio/Lab 9: Programmed Replication continues
• Our second exam will take place during our first meeting back from Thanksgiving break. I'll have details next Wednesday. Note that we do not meet at all during the Thanksgiving week, but I will try to be around some that Monday and Tuesday.
• Functions
• In-class Exercise 21 - (10 lecture assignment points) due before the end of class.

We will work together to continue to develop our model that creates stacks of poker chips. We already have code that will create stacks of chips where each chip is randomly moved a bit so the stack looks "imperfect". We will work together to add functionality that creates new random stacks each time we add, and allows us to use a different number of chips in each stack.

Please demonstrate your program or submit your Python model and image by email before you leave class. Email submissions should use a meaningful subject line, clearly indicating the course number and assignment name.

Due at the start of class, Wednesday, November 18.

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 21 Assignment , Joe Student). We will discuss these questions at the start of class, so no late submissions are accepted.

We revisit questions from the previous lecture assignment, now working with Python functions.

1. 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)
2. 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)
3. 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)

Terminology

• formal parameter
• actual parameter
• passing parameters
• function return values
• return statement

Examples