Return Function Tests
Each example assumes the students file name is example#.py
replacing # with the actual example number. You can call the functions by importing the student file name of your choice.
Example 1 - Add Five
Students write an function named add_five()
that takes an integer as a parameter and returns 5 plus the parameter value.
Grading Tests:
Sample Solution:
Example 2 - Average
Students write a function that takes 5 values as parameters and returns the average value of the 5 values. The function must be named average()
and it must have 5 parameters.
Example: Calling average(1, 5, 7, 4, 10)
would return 5.4
.
Note: Almost Equal assertion is used with a delta value as tolerance when comparing values.
Grading Tests:
Sample Solution:
Example 3 - Repeats
Students write a function that takes a parameter. If the String parameter has a double letter (i.e. contains the same letter twice in a row) then it should return true. Otherwise, it should return false.
This function must be named has_repeat()
and have a parameter. This function must return a boolean
.
Grading Tests:
Sample Solution:
Last updated