Functions

CS 106

POGIL Activity

Exercise 6.a

Activities for CS1 in Python, Defining Functions

Work through the following models:

  1. Model 1. Flow of Execution (code: model one)
  2. Model 2. Passing Arguments (code: model two)
  3. Model 3. Returning Values (code: model three)

Function Exercises

Exercise 6.b.1

Write a function that receives the width and height of a rectangle and returns the area of that rectangle.

Write additional code that uses (aka invokes) this function to print the area of a unit square.

Exercise 6.b.2

Write a function that receives an integer and returns a list of that many integers read from the user.

Write additional code that uses (aka invokes) this function to create a list of three integers.

Exercise 6.b.3

Download this starter code and complete the following exercises:

  1. Modify the draw_smiley function to draw the second eye.
  2. Modify the main program to add a second smiley face just above the first one.
  3. Draw a whole “tower” of smiley faces, alternating colors.
  4. Write a function that draws a “tower” of smileys. The function should receive the starting position and the number and size of smileys from the calling program. Use this function to draw several smiley towers.

Reflection

Exercise 6.c

As an exercise in finding your vocation, list examples of the things that you most enjoy doing and things that the world most needs to have done.

My deep gladness:

The world’s deep hunger:

Consider your lists in the context of F. Buechner’s description of a vocation.