# 18.10. Chapter Assessment¶

The function mySum is supposed to return the sum of a list of numbers (and 0 if that list is empty), but it has one or more errors in it. Use this space to write test cases to determine what errors there are. You will be using this information to answer the next set of multiple choice questions.

Which of the following cases fail for the mySum function?

• an empty list
• Correct, 0 is not returned if the function is given an empty list.
• a list with one item
• Incorrect, a list with one item returns the correct value.
• a list with more than one item
• Correct, a list with more than one item does not provide the correct response.

Are there any other cases, that we can determine based on the current structure of the function, that also fail for the mySum function?

• Yes
• Incorrect. Though it is possible that the function could have more issues, we can't tell if other cases would fail (such as combining integers and floats) due to the current issues.
• No
• Correct. At the moment we can't tell if other cases would fail (such as combining integers and floats), but it is possible that the function could have more issues once the current issues are fixed.
The class Student is supposed to accept two arguments in its constructor:
1. A name string

2. An optional integer representing the number of years the student has been at Michigan (default:1)

Every student has three instance variables:
1. self.name (set to the name provided)

2. self.years_UM (set to the number of years the student has been at Michigan)

3. self.knowledge (initialized to 0)

There are three methods:
• .study() should increase self.knowledge by 1 and return None

• .getKnowledge() should return the value of self.knowledge

• .year_at_umich() should return the value of self.years_UM

There are one or more errors in the class. Use this space to write test cases to determine what errors there are. You will be using this information to answer the next set of multiple choice questions.

Which of the following cases fail for the Student class?

• the method study does not return None
• Incorrect, the method study does return None.
• the optional integer in the constructor is not optional
• Incorrect, the integer for number of years is optional.
• the attributes/instance variables are not correctly assigned in the constructor
• Correct! The constructor does not actually use the optional integer that is provided. Instead it sticks with using the default value.
• the method study does not increase self.knowledge
• Correct! Study does not increase the self.knowledge.
• the method year_at_umich does not return the value of self.years_UM
• Incorrect, year_at_umich does return the value assigned to self.years_UM.

Are there any other cases, that we can determine based on the current structure of the class, that also fail for the Student class?

• Yes
• Correct! There is an issue with the getKnowledge method because it returns None when self.knowledge is 0, even though it returns the correct value when self.knowledge is non-zero.
• No
• Incorrect, there are more cases that fail. Try finding those other cases!