16.16. Group Work - Classes, constructors, attributes, and methods

Please join a research study to help us test new approaches to learning programming!

Hi! We are a team of researchers in Professor Ericson’s Lab at UMSI!

The Project

You are invited to participate in a research study about how Parsons problems (a type of coding puzzle) may help CS entry-level learning. You must be at least 18 to participate.
Your participation will help more students become successful in computing courses in a low-cost, scalable, and easily adopted way.

What Will Occur

This study takes 50 minutes to one hour to finish. The study materials include:

Each section must be completed in order. After finishing one part, you can click the link provided under "What to do next" to the next part.

Confidentiality of Information

All the data we collect will be de-identified. We will not collect any identifiable data such as demographic information.

Who to Contact

If you have any questions about the study, please contact Xinying Hou at xyhou@umich.edu with “[Parsons Problem Study]” included in the email subject.

We greatly appreciate your help!

Note

Click on the following link 👉 Basic Knowledge Review 👈 to start!


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

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.

Learning Objectives

Students will know and be able to do the following.

Content Objectives:

Look the code below. It defines a class. it also declares methods which are functions that are defined inside of a class. One of the methods is automatically called when a new object is created by the class. One of the methods is automatically called when you print an object of the class.

16.16.1. A Book Class

Run the following code

Look at the class definition. It starts with the keyword class. Then answer the following questions.

Q-4: Describe in your own words what the __init__ method does.

Q-6: Describe in your own words what the __str__ method does.

Q-9: Describe in your own words what is/are the difference(s) between a function and a method.

Put the code blocks in order below to create a class Person with a constructor (__init__) method that takes a first and last name and a __str__ method to return a string with the first and last name separated with a space.

Q-12: Describe in your own words what self means.

16.16.2. Create More Book Objects

Change the following main function to create a third book object called b3 with a title of “1984” and author “George Orwell”. Print out the values using the print function in the main.

Change the following main function to add a person object with your first and last name.

16.16.3. Add a Method to a Class

Change the following Person class to add an initials method that returns a string with the first letter in the first name and the first letter in the last name in lowercase.

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.

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.

You have attempted of activities on this page