Unfortunately, I can't give you the condition of the problem, but I can briefly describe it we need to create two classes:
- The first class creates an exam ticket. The teacher writes the name of the subject, the correct answers to the test and the minimum percentage for successful completion.
- The second grade is the student's test.
class Testpaper:
def __init__(self, subject, markscheme, pass_mark):
self.subject = subject
self.markscheme = markscheme
self.pass_mark = pass_mark
class Student:
def __init__(self, tests_taken = {}):
self._tests_taken = tests_taken
@property
def tests_taken(self):
if self._tests_taken == {}:
self._tests_taken = "No tests taken"
return self._tests_taken
else:
return self._tests_taken
def take_test(self, testpaper, answers):
self._tests_taken = {}
pass_mark = 0
for answer in answers:
if answer in testpaper.markscheme:
percent = 100 / len(testpaper.markscheme)
pass_mark += percent
if pass_mark >= int(testpaper.pass_mark[:-1]):
self._tests_taken[testpaper.subject] = f"Passed! ({round(pass_mark)}%)"
return self._tests_taken
else:
self._tests_taken[testpaper.subject] = f"Failed! ({round(pass_mark)}%)"
return self._tests_taken
Here's what I need to check:
paper1 = Testpaper("Maths", ["1A", "2C", "3D", "4A", "5A"], "60%")
paper2 = Testpaper("Chemistry", ["1C", "2C", "3D", "4A"], "75%")
paper3 = Testpaper("Computing", ["1D", "2C", "3C", "4B", "5D", "6C", "7A"], "75%")
student1 = Student()
student2 = Student()
paper3 = Testpaper('Computing', ['1D', '2C', '3C', '4B', '5D', '6C', '7A'], '75%')
student2 = Student()
student3 = Student()
student2.take_test(paper3, ['1A', '2C', '3A', '4C', '5D', '6C', '7B'])
print(student3.tests_taken)
student3.take_test(paper1, ['1C', '2D', '3A', '4C', '5A'])
student3.take_test(paper3, ['1A', '2C', '3A', '4C', '5D', '6C', '7B'])
print(student3.tests_taken)
print(paper3.subject)
print(paper3.markscheme)
print(paper3.pass_mark)
This is my output:
No tests taken
{'Computing': 'Failed! (43%)'}
Computing
['1D', '2C', '3C', '4B', '5D', '6C', '7A']
75%
And this is the correct output:
No tests taken
{'Maths': 'Failed! (20%)', 'Computing': 'Failed! (43%)'}
Computing
['1D', '2C', '3C', '4B', '5D', '6C', '7A']
75%
What I must change?