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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!