Last active
September 17, 2019 13:15
-
-
Save leyyce/bf7f9b37bf96b7dd896d9caf3bee083f to your computer and use it in GitHub Desktop.
Student Credits Management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from student_register import StudentRegister | |
from student import Student | |
def main(): | |
register = StudentRegister("Bachelor CS 2019") | |
napoleon = Student('Napoleon', 1, 20) | |
snowball = Student('Snowball', 2, 22) | |
squealer = Student('Squealer', 3, 19) | |
napoleon.add_module('Front End Design', 3) | |
napoleon.add_module('Intro to Computer Programming', 3) | |
napoleon.add_module('Statistics and Probability', 3) | |
napoleon.add_module('Operating Systems', 2) | |
snowball.add_module('Discrete Mathematics', 3) | |
snowball.add_module('Database Systems', 3) | |
snowball.add_module('Cooperative Education', 6) | |
snowball.add_module('Web Dev. and Programming', 3) | |
squealer.add_module('Seminar', 1) | |
squealer.add_module('Digital Marketing', 3) | |
squealer.add_module('Organization and ISM', 1) | |
register.add_student(napoleon) | |
register.add_student(snowball) | |
register.add_student(squealer) | |
register.add_student(Student('Yannic', 4, 0)) | |
y = register.get_student(4) | |
y.add_module('Running module') | |
y.add_module('Programming 1') | |
y.add_module('Digital Networks', 11) | |
y.set_credits('Programming 1', 1) | |
y.add_module('Network Security', 111) | |
y.add_module('Another running module') | |
register.list_students() | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
Listing all students in the register "Bachelor CS 2019" | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
Napoleon | |
--------------------------------------------------------------------------- | |
1: Front End Design 3 credits | |
2: Intro to Computer Programming 3 credits | |
3: Statistics and Probability 3 credits | |
4: Operating Systems 2 credits | |
=========================================================================== | |
Total: 11 credits | |
=========================================================================== | |
Snowball | |
--------------------------------------------------------------------------- | |
1: Discrete Mathematics 3 credits | |
2: Database Systems 3 credits | |
3: Cooperative Education 6 credits | |
4: Web Dev. and Programming 3 credits | |
=========================================================================== | |
Total: 15 credits | |
=========================================================================== | |
Squealer | |
--------------------------------------------------------------------------- | |
1: Seminar 1 credits | |
2: Digital Marketing 3 credits | |
3: Organization and ISM 1 credits | |
=========================================================================== | |
Total: 5 credits | |
=========================================================================== | |
Yannic | |
--------------------------------------------------------------------------- | |
1: Running module [PENDING] | |
2: Programming 1 1 credits | |
3: Digital Networks 11 credits | |
4: Network Security 111 credits | |
5: Another running module [PENDING] | |
=========================================================================== | |
Total: 123 credits (+ 2 module(s) pending) | |
=========================================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student: | |
def __init__(self, name: str, enrollment_number: int, age: int): | |
self.name = name | |
self.enrollment_number = enrollment_number | |
self.age = age | |
self.modules = {} | |
# Other attributes go here... | |
def add_module(self, module_name: str, creds: int = None): | |
self.modules[module_name] = creds | |
def set_credits(self, module_name: str, score: int): | |
if module_name in self.modules.keys(): | |
self.modules[module_name] = score | |
else: | |
print(f'Student {self.name} not enrolled in a module with the name "{module_name}". Credits not set!\n') | |
def print_scores(self, length: int = 75): | |
print(self.name) | |
print('-' * length) | |
no = 1 | |
total = 0 | |
for mod, score, in self.modules.items(): | |
mod_text = f'{no}: {mod}' | |
if score is not None: | |
credit_text = f'{score} credits' | |
else: | |
credit_text = '[PENDING]' | |
padding = ' ' * (length - (len(mod_text) + len(credit_text))) | |
print(mod_text + padding + credit_text) | |
if score is not None: | |
total += score | |
no += 1 | |
print('=' * length) | |
if None not in self.modules.values(): | |
total_str = f'Total: {total} credits' | |
else: | |
total_str = f'Total: {total} credits (+ {list(self.modules.values()).count(None)} module(s) pending)' | |
print(total_str) | |
print('=' * length + '\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from student import Student | |
class StudentRegister: | |
def __init__(self, name: str): | |
self.name = name | |
self.register = {} | |
def add_student(self, student: Student): | |
self.register[student.enrollment_number] = student | |
def get_student(self, enrollment_number: int): | |
return self.register[enrollment_number] | |
def list_students(self, width: int = 75): | |
print('~' * width) | |
print(f'Listing all students in the register "{self.name}"') | |
print('~' * width) | |
for student in self.register.values(): | |
student.print_scores(width) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment