#๐Ÿ”’ failing this doctest

23 messages ยท Page 1 of 1 (latest)

ivory frost
#

help implementing a function

fresh sentinelBOT
#

@ivory frost

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

ivory frost
#
class Staff(Person):
    '''
        >>> C = Catalog()
        >>> C._loadCatalog("cmpsc_catalog_small.csv")
        >>> s1 = Staff('Jane Doe', '214-49-2890')
        >>> s1.getSupervisor
        >>> s2 = Staff('John Doe', '614-49-6590', s1)
        >>> s2.getSupervisor
        Staff(Jane Doe, 905jd2890)
        >>> s1 == s2
        False
        >>> s2.id
        '905jd6590'
        >>> p = Person('Jason Smith', '221-11-2629')
        >>> st1 = s1.createStudent(p)
        >>> isinstance(st1, Student)
        True
        >>> s2.applyHold(st1)
        'Completed!'
        >>> st1.registerSemester()
        'Unsuccessful operation'
        >>> s2.removeHold(st1)
        'Completed!'
        >>> st1.registerSemester()
        >>> st1.enrollCourse('CMPSC 132', C)
        'Course added successfully'
        >>> st1.semesters
        {1: CMPSC 132}
        >>> s1.applyHold(st1)
        'Completed!'
        >>> st1.enrollCourse('CMPSC 360', C)
        'Unsuccessful operation'
        >>> st1.semesters
        {1: CMPSC 132}
    '''
    def __init__(self, name, ssn, supervisor=None):
        # YOUR CODE STARTS HERE
        super().__init__(name, ssn)
        self.supervisor = None


    def __str__(self):
        # YOUR CODE STARTS HERE
        return f"Staff({self.name}, {self.id})"

    __repr__ = __str__


    @property
    def id(self):
        # YOUR CODE STARTS HERE
        initials = ''.join([name_part[0].lower() for name_part in self.name.split()])
        staff_id = f"905{initials}{self.get_ssn()[-4:]}"
        return staff_id
    
    @property   
    def getSupervisor(self):
        # YOUR CODE STARTS HERE
        return self.supervisor

    def setSupervisor(self, new_supervisor):
        # YOUR CODE STARTS HERE
        if isinstance(new_supervisor, Staff):
            self.supervisor = new_supervisor
            return "Completed!"
        return None

    def applyHold(self, student):
        # YOUR CODE STARTS HERE
        if isinstance(student, Student):
            student.hold = True
            return "Completed!"
        return None

    def removeHold(self, student):
        # YOUR CODE STARTS HERE
        if isinstance(student, Student):
            student.hold = False
            return "Completed!"
        return None

    def unenrollStudent(self, student):
        # YOUR CODE STARTS HERE
        if isinstance(student, Student):
            student.active = False
            return "Completed!"
        return None

    def createStudent(self, person):
        # YOUR CODE STARTS HERE
        if isinstance(person, Person):
            return Student(person.name, person.get_ssn(), "Freshman")
        return None
#

Failed example:
s2.getSupervisor
Expected:
Staff(Jane Doe, 905jd2890)
Got nothing

clear wasp
#

You are not using all parameters __init__ accepts

ivory frost
#

can you explain

clear wasp
#

in def __init__ you are accepting three arguments, but you are not using all of them

ivory frost
clear wasp
#

yep

ivory frost
clear wasp
#

assign the value you're storing in self to the value you were given

ivory frost
#

?

clear wasp
#

yep

ivory frost
clear wasp
#

Shows which error exactly are you getting

ivory frost
#

its correct

#

thank you i appreciate it

#

!close

fresh sentinelBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.