Question
Hello, I am having hard time figuring out how to write code for the def header. I started with @classmethod def header(cls, ).
Hello,
I am having hard time figuring out how to write code for the def header.
I started with
@classmethod
def header(cls, ). <- I am not sure if I need an argument here or not
return (f"{'ID':<10} {'Last Name':<16} .....{'Course':<42}") + '/n' + '========.....'
Here is my assignment instruction:
__str()__: - this method should output a formatted string such that printing multiple Student objects will line up. Example results for 3 objects (fields: id, lastName, firstName, gpa, courses)
__repr()__: - we will not directly use this method, but it should have an output similar to __str__. However, the column formatting is not necessary. You can use commas in between fields
header() signature:
def signature(): - this method returns a string that can be used as a header for the results of the __str__ method. - notice that this is a class method because there is no "self" parameter, so it will be called using Student.header().
- example result:
ID Last Name First Name GPA Courses
=======================================
Hint and tips:
-
For Student.header(), you can use a character to inject a new line between the header text and the bar of equal signs.
-
Speaking of equal sign bar... Dont forget you can create a string of consecutive characters using the * operator. Example: 'A'*10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started