In an early function, let's call it a, i have to make sure that the a function doesn't produce an answer that is too small (let's say, answer must be bigger than 10).
But later on, in a second function b (which uses function a as one of its inputs), it is okay if the same answer that is being modified is smaller than the earlier assert statement.
Is there a way to do this?
When function b produced an answer that was too small, I tried to save how small the answer was in variable, but I'm still getting assert errors when I run doctest.
def grade_on_project(student_project_score, max_score, overall_score):
project_grade = student_project_score / max_project_score
assert project_grade > 0.6 # (student fails the class if any of their scores on a project are too low)
overall_score +=student_project_score
return overall_score
def who_fails_first(operation, person1, person2)
if (operation(person1, max_score, person1) <= 150 and (operation(person2, max_score, overall_score) > 150:
print(student 1 failed)
if (operation(person2, max_score, overall_score) <= 150 and (operation(person1, max_score, overall_score) > 150:
print(student 2 failed)
who_fails_first(grade_on_project, 5, 9)
function adescribes a behavior that you expect for a given set of inputs. That contract between input and expected behavior should be (and as you're finding, needs to be) independent of the context in which it's called.