Skip to main content

Worksheet 5.18 Group Work: Functions

It is best to use a POGIL approach with the following. In POGIL students work in groups on activities and each member has an assigned role. For more information see https://cspogil.org/Home.

Note 5.18.1.

If you work in a group, have only one member of the group fill in the answers on this page. You will be able to share your answers with the group at the bottom of the page.

Section 5.18.1 Learning Objectives

Students will know and be able to do the following.
Content Objectives:
  • Learn how to display a value in Python using print.
  • Math terms for functions to their definitiions.
  • Recognize common symbols (:, #), operators (+, -, /), and keywords (def, return) in Python.
Process Objectives:

Subsection 5.18.1.1 Print and Function Basics

Look at the code below and predict what it will print.

Activity 5.18.1.

Activity 5.18.2.

Activity 5.18.3.

Run the Python code below and then answer the following questions.

Activity 5.18.4.

Run the code below to see what it prints and then use it to answer the following questions.

Note 5.18.2.

You do not declare the type of a variable in Python. Python requires that all statements that are part of the body of a function must be indented. Use four spaces to indent.

Activity 5.18.5.

Activity 5.18.6.

Activity 5.18.7.

Activity 5.18.8.

Activity 5.18.9.

Drag the blocks from the left and put them in the correct order on the right to describe the order the function calls and functions execute.

Subsection 5.18.1.2 Parts of a Function and Function Calls

Activity 5.18.10.

Activity 5.18.11.

Activity 5.18.12.

Subsection 5.18.1.3 Writing Function Calls

Activity 5.18.13.

Modify the code below to print the last two lines twice by only adding one line. That line can’t call the print function.

Activity 5.18.14.

Modify the code below to print β€œHello Students” by adding one line and without calling the print function in that line.

Subsection 5.18.1.4 Function Order

Look at the Python code below. What do you think will happen when you run the following code?

Activity 5.18.15.

Run the code below to see what happens when you try to call a function before it is defined.

Note 5.18.3.

Python processes the code in a file from left to right and from the first line to the last line. All functions must be defined before they are called.

Activity 5.18.16.

Drag the blocks from the left and put them in the correct order on the right to define a function print_greeting that asks for your name and prints β€œHello Name”. Then define a main function that calls print_greeting. Be sure to also call the main function. Note that you will have to indent the lines that are in the body of each function. Click the Check button to check your solution.

Subsection 5.18.1.5 Special Characters and Keywords

Activity 5.18.17.

Activity 5.18.18.

Activity 5.18.19.

If you worked in a group, you can copy the answers from this page to the other group members. Select the group members below and click the button to share the answers.
You have attempted of activities on this page.
The Submit Group button will submit the answer for each each question on this page for each member of your group. It also logs you as the official group submitter.