Skip to content

Commit

Permalink
Add part 2 solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dayan committed Nov 19, 2022
1 parent 2bfa04e commit 0bdb1e5
Show file tree
Hide file tree
Showing 9 changed files with 1,405 additions and 9 deletions.
1,225 changes: 1,216 additions & 9 deletions python_series_solutions.ipynb

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions solutions_part2/exam1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import grading

student_results = {
'John': 3,
'Mary': 9,
'Peter': 5
}

if __name__ == "__main__":
print(__name__)
for s_name, s_grade in student_results.items():
s_feedback = grading.comment_grade(s_grade, mode='negative_reinforcement')
print(f'Feedback for {s_name}: {s_feedback}')
37 changes: 37 additions & 0 deletions solutions_part2/grading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def comment_grade(grade: int, mode: str = 'normal') -> str :
''' Provide a feedbac k according to the grade value
Parameters
----------
grade
The amount of distance traveled
mode
The feedback mode, either "normal" (default) or "positive_reinforcement"
Returns
-------
comment
The grade feedback
Examples
--------
>>> comment_grade(5)
'Grade high enough'
'''
if grade < 5:
return('Grade too low')
elif grade > 5:
if mode == 'normal':
return('Grade high enough')
elif mode == 'positive_reinforcement':
return('Well done, keep going!')
else:
raise ValueError('The mode should be "normal" or "positive_reinforcement"')

def test_comments():
assert comment_grade(0, mode='normal') == 'Grade too low'
assert comment_grade(2, mode='normal') == 'Grade too low'
#assert comment_grade(5, mode='normal') == 'Grade high enough'
#assert comment_grade(5, mode='positive_reinforcement') == 'Well done, keep going!'
assert comment_grade(10, mode='normal') == 'Grade high enough'
assert comment_grade(10, mode='positive_reinforcement') == 'Well done, keep going!'
11 changes: 11 additions & 0 deletions solutions_part2/step1/exam1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import grading

student_results = {
'John': 3,
'Mary': 9,
'Peter': 5
}

for s_name, s_grade in student_results.items():
s_feedback = grading.comment_grade(s_grade, mode='negative_reinforcement')
print(f'Feedback for {s_name}: {s_feedback}')
24 changes: 24 additions & 0 deletions solutions_part2/step1/grading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def comment_grade(grade: int, mode: str = 'normal') -> str :
''' Provide a feedbac k according to the grade value
Parameters
----------
grade
The amount of distance traveled
mode
The feedback mode, either "normal" (default) or "positive_reinforcement"
Returns
-------
comment
The grade feedback
'''
if grade < 5:
return('Grade too low')
elif grade > 5:
if mode == 'normal':
return('Grade high enough')
elif mode == 'positive_reinforcement':
return('Well done, keep going!')
else:
raise ValueError('The mode should be "normal" or "positive_reinforcement"')
11 changes: 11 additions & 0 deletions solutions_part2/step2/exam1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import grading

student_results = {
'John': 3,
'Mary': 9,
'Peter': 5
}

for s_name, s_grade in student_results.items():
s_feedback = grading.comment_grade(s_grade, mode='negative_reinforcement')
print(f'Feedback for {s_name}: {s_feedback}')
24 changes: 24 additions & 0 deletions solutions_part2/step2/grading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def comment_grade(grade: int, mode: str = 'normal') -> str :
''' Provide a feedbac k according to the grade value
Parameters
----------
grade
The amount of distance traveled
mode
The feedback mode, either "normal" (default) or "positive_reinforcement"
Returns
-------
comment
The grade feedback
'''
if grade < 5:
return('Grade too low')
elif grade >= 5:
if mode == 'normal':
return('Grade high enough')
elif mode == 'positive_reinforcement':
return('Well done, keep going!')
else:
raise ValueError('The mode should be "normal" or "positive_reinforcement"')
32 changes: 32 additions & 0 deletions solutions_part2/step3/grading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def comment_grade(grade: int, mode: str = 'normal') -> str :
''' Provide a feedbac k according to the grade value
Parameters
----------
grade
The amount of distance traveled
mode
The feedback mode, either "normal" (default) or "positive_reinforcement"
Returns
-------
comment
The grade feedback
'''
if grade < 5:
return('Grade too low')
elif grade > 5:
if mode == 'normal':
return('Grade high enough')
elif mode == 'positive_reinforcement':
return('Well done, keep going!')
else:
raise ValueError('The mode should be "normal" or "positive_reinforcement"')

def test_comments():
assert comment_grade(0, mode='normal') == 'Grade too low'
assert comment_grade(2, mode='normal') == 'Grade too low'
assert comment_grade(5, mode='normal') == 'Grade high enough'
assert comment_grade(5, mode='positive_reinforcement') == 'Well done, keep going!'
assert comment_grade(10, mode='normal') == 'Grade high enough'
assert comment_grade(10, mode='positive_reinforcement') == 'Well done, keep going!'
37 changes: 37 additions & 0 deletions solutions_part2/step4/grading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def comment_grade(grade: int, mode: str = 'normal') -> str :
''' Provide a feedbac k according to the grade value
Parameters
----------
grade
The amount of distance traveled
mode
The feedback mode, either "normal" (default) or "positive_reinforcement"
Returns
-------
comment
The grade feedback
Examples
--------
>>> comment_grade(5)
'Grade high enough!'
'''
if grade < 5:
return('Grade too low')
elif grade >= 5:
if mode == 'normal':
return('Grade high enough')
elif mode == 'positive_reinforcement':
return('Well done, keep going!')
else:
raise ValueError('The mode should be "normal" or "positive_reinforcement"')

def test_comments():
assert comment_grade(0, mode='normal') == 'Grade too low'
assert comment_grade(2, mode='normal') == 'Grade too low'
assert comment_grade(5, mode='normal') == 'Grade high enough'
assert comment_grade(5, mode='positive_reinforcement') == 'Well done, keep going!'
assert comment_grade(10, mode='normal') == 'Grade high enough'
assert comment_grade(10, mode='positive_reinforcement') == 'Well done, keep going!'

0 comments on commit 0bdb1e5

Please sign in to comment.