Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this is the assigment outline but i keep getting the error the code is ant the b

ID: 3830497 • Letter: T

Question

this is the assigment outline but i keep getting the error the code is ant the buttom and the error is the last part.

CS    112,        Lab 13   –      Exercise –      Classes, Exceptions

Due:    Moday               May     1st,        11:59pm

              

              

Files:      

                   

Create your     own      file        with     our        convention      (userID_2xx_L13.py).

You       should download         the        tester file        from     Piazza and       run it            as          always:                    

   

                                       python3 tester13L.py yourfile.py                         just these classes    

                    o Note: you can only use three class   names as the targeted tests for this lab:

Course               testing everything       with     Course               class               w/o      exception         behavior

Transcript testing    everything       with     Transcript     class               w/o      exception         behavior,          must    have               Course               class     implemented

CourseError testing CourseError class     and       the               exception         behavior           of          Course               class               and       Transcript     class    

         

As          this       is           an          Exercise,          you       can        read     any       and       all               materials,         ask        us          questions,        talk       with     other   students,               and       learn    however           you       best      learn    in           order   to           solve               the        task.     Just       create your     own      solution            from     those               experiences,   and       turn      in           your     work.  

                   

                   

Classes              allow   us          to           define entirely             new      types. We               might think    of           each     type      in           Python               as          a             set               of           values, and       we         use        a             class     declaration      to               describe            how      to           build    and       interact             with     all          the               values of           this       brand new      type.     We        will       often    need     at               minimum         a             constructor     (telling               us          what    instance               variables          to           always create),              __str__ method             (telling               Python               how      to           represent         the        thing    as          a               string),              and       then     any       extra    methods           that      we         deem               useful ways    of           interacting      with     the        new      values.

              

                   

Turning It     In   

Add      a             comment          at           the        top        of           the        file        that               indicates          your     name, userID,               G#,        lab         section,             a               description     of           your     collaboration partners,           as          well      as               any       other   details you       feel       like       sharing.             Please also               mention            what    was      most    helpful for         you.      Once    you       are               done,   run        the        testing script   once     more    to           make   sure      you               didn't break   things while   adding these   comments.      If            all          is               well,     go          ahead and       turn      in           just       your     one       .py         file               you've been     working            on          over     on          BlackBoard     to           the               correct               lab         assignment.    We        have     our        own      copy     of               the        testing file        that      we'll     use,       so          please don't    turn      that               in           (or        any       other   extra    files),   as          it            will       just       slow               us          down.

                   

                   

What         can   I         use?

You       may      NOT     import any       module.                            There are        no               further               restrictions     –             use        this       time     to           learn    how               to           create classes and       create objects               of           those   classes.              

                   

                   

Grading    Rubric      

                   

Pass                                        shared     test                                            cases                                                                                                                    4x25 (zero points                                             for hard-coding)                                                

-----------------------------------     TOTAL:                                                                                                        100             

              

Task        1      -       Course

A            Course               represents       a             specific              course record as          those               appeared          on          your     transcript.  

class Course:               Define               the               Course               class.                  

def   __init__(self,    number,     credit,     grade): Course               constructor.    All         three    parameters     must    be stored to           instance            variables          of           the        same    names (number,            credit,              and       grade).                             

o number ::             str.       Represents      course number,            like       "CS112"            or         "MATH113".       o credit    ::             int.       Represents      credit hours.                 You       can        assume              it       will       always be          a             positive             integer.              o grade   ::            str.                      Represents      letter   grade. Can       only      be       'A','B','C','D','F',   or          'IP'.                   If            the        provided       grade   is           not        one       of           these   (for       example,       grade ==    "K"),     then     raise    a             CourseError with     the       message           "bad     grade   'K'".    (You     can        skip      this       exception-raising       part      until     later).                               

def   __str__(self):          returns              a             human-centric string representation.            If           number=="CS112",       credit==4,       and grade=="A",    then     the        returned           string must    be          "CS112: credit      4,    grade A"          (note   the        four      single spaces).

def   __eq__(self,other):            we         want    to           check   that      two courses             are        equal   (our      self     and       this       other   course). We        compare           each     instance            variable             like       so          (this is           the        definition!)                    return self.number==other.number    and self.credit==other.credit    and    self.grade==other.grade                           

def   is_passing(self): checks whether            this       course has passed or          not        according         to           grade.                 Return False   if the        grade   is           'F'        or          'IP';    return True     otherwise.      

              

              

Task        2      -       Transcript  

This      represents       a             group of           Course               values as          a             list               (named             courses).          We        can        then     dig        through             this               list        for         useful course information    and       calculations    by               calling the        methods           we're   going   to           implement.     

class Transcript: Define the        Transcript class.   

def   __init__(self):       Transcript     constructor.    Create the        only instance            variable,            a             list        named courses,            and initialize           it            to           an          empty list.       This      means that      we can        only      create an          empty Transcript     and       then     add       items to           it            later     on.        

def   __str__(self):          returns              a             human-centric string representation.            We'll    choose a             multi-line representation             (slightly            unusual)           that      contains "Transcript:"            on          the        first      line,      and       then     each successive       line       is           a             tab,       the       str()   representation of           the        next      Course               object in           self.courses,              and then     a             newline             each     time.    This      means that      the        last character          of           the        string is           guaranteed      to           be          a newline             (regardless      of           whether            we         have     zero      or many   Course               values).            

def   __eq__(self,other):            we         want    to           check   that      two transcripts      are        equal   (our      self     and       this       other   transcript). The       only      things that      we         need     to           compare           are        their lists      of           courses.                           Note:   you       can        compare           two lists      l1          and       l2          directly              as          l1==l2               but        this will       rely       on          your     implementation          of           __eq__()          for Course               class     since    we         are        comparing       two       lists      of courses.           

def   add_course(self, course):          append              the        argument course               to           the        end       of           self.courses.              In order   to           ensure every   course number             is           unique,              if our        transcript         already              has        a             course of           the        same number             (for       example            'ENGH101'),    raise    a CourseError with     the        message          "duplicate     course number               'ENGH101'".    (You     can        skip      this       exception-raising part      until     later). • def course_by_number(self, number):          Look through             all          storedCourse               objects               in self.courses.             

Return the        Course               object whose number             matches            the               number               argument.        If            no          match, return None.                   You       can        assume              that      every   course number             is               unique in           a             transcript.       

def   course_by_grade(self,   grade):            search through self.courses               in           order, return a             list        of           Course object in           this       Transcript     that      is           of           this       grade. If no          match, return an          empty list.       • def total_passing_credit(self):       Look    through             all          stored Course               objects               in           self.courses.             

Return total     credit hours   of           all          courses             that      have    a               passing             grade.                              

              

Task        3      –      CourseError

The       CourseError class     extends             the        notion of           an          Exception               (note   the        (Exception) part      of           the        class     signature          line).               We're making              our        own      exception         that      stores a               single string message.                        

                   

class CourseError(Exception): Define the        CourseError class     to           be               a             child     of           Exception       class     (by        putting              Exception               in           the        parentheses    as          shown).            

def   __init__(self,msg):            Constructor.   Store    msg        to           an instance            variable             named msg.      

def   __str__(self):          human-centric             representation             of CourseError is           just      self.msg         

              

If            you       skipped             the        two       exception-raising       parts    above, you               should now      go          back     and       add       those   checks/raises.              The               test       cases   for        CourseError will       go          back     and       check   if               those   parts    correctly           did        so.

this id the code

class Course:
   def __init__(self, number, credit, grade):
       self.number = number
       self.credit = credit
       gradeList = ['A', 'B', 'C', 'D', 'F', 'IP']
       if grade in gradeList:
           self.grade = grade
       else:
           raise CourseError("bad grade '" + str(grade) + "'")
          
   def __str__(self):
       return self.number + ": credit " + str(self.credit) + ", grade " + self.grade
   def __eq__(self,other):
       return self.number==other.number and self.credit==other.credit and self.grade==other.grade
   def is_passing(self):
       return not (self.grade == 'F' or self.grade == 'IP')

class Transcript:
   def __init__(self):
       self.courses = []
   def __str__(self):
       transcript = "Transcript: "
       for course in self.courses:
           transcript += str(course) + " "
       return transcript
   def __eq__(self,other):
       return self.courses == other.courses
   def add_course(self, course):
       for crs in self.courses:
           if course == crs:
               raise CourseError("duplicate course number '" + course.number + "'")
       self.courses.append(course)
  
   def course_by_number(self, number):
       for course in self.courses:
           if course.number == number:
               return course
       return None
   def course_by_grade(self, grade):
       grade_list = []
       for course in self.courses:
           if course.grade == grade:
               grade_list.append(course)
       return grade_list
   def total_passing_credit(self):
       total_hours = 0
       for course in self.courses:
           if course.is_passing():
               total_hours += course.credit
               return total_hours
class CourseError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return self.msg
  
c1 = Course("CS112",4,"A")
print(c1.is_passing())
c2 = Course("ENGH101",3,"B")
print (c1==c2)
c3 = Course("MATH113",4,"IP")
t = Transcript()
print(str(t))

t.add_course(c1)
t.add_course(c2)
t.add_course(c3)
print(str(t))

t.add_course(Course("GAME101",3,"A"))
t.course_by_number("CS112")
print(t.course_by_number("CS112"))
t.course_by_number("CS114")
print(t.course_by_number("CS114"))
ans = t.course_by_grade("A")
print(len(ans))

c = Course("CS101",2,"Y") # this should raise a CourseError

error that i keep getting

C:UserskomalDesktop>tester.py sshah38_223_L13.py
True
False
Transcript:

Transcript:
CS112: credit 4, grade A
ENGH101: credit 3, grade B
MATH113: credit 4, grade IP

CS112: credit 4, grade A
None
2
Exception in loadingsshah38_223_L13.py:
bad grade 'Y'
Run your file without the tester to see the details
========================================
Traceback (most recent call last):
File "C:UserskomalDesktop ester.py", line 554, in <module>
main()
File "C:UserskomalDesktop ester.py", line 348, in main
print(" Test cases: %d/%d passed" % (passed1,tried1) )
TypeError: %d format: a number is required, not NoneType

C:UserskomalDesktop>

Explanation / Answer

Firstly you doesn't seem to have Exception class
here is full code:

class CourseError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return self.msg

class Course:
def __init__(self, number, credit, grade):
self.number = number
self.credit = credit
gradeList = ['A', 'B', 'C', 'D', 'F', 'IP']
if grade in gradeList:
self.grade = grade
else:
raise CourseError("bad grade '" + str(grade) + "'")
  
def __str__(self):
return self.number + ": credit " + str(self.credit) + ", grade " + self.grade
  
def __eq__(self,other):
return self.number==other.number and self.credit==other.credit and self.grade==other.grade
def is_passing(self):
return not (self.grade == 'F' or self.grade == 'IP')

class Transcript:
def __init__(self):
self.courses = []
def __str__(self):
transcript = "Transcript: "
for course in self.courses:
transcript += str(course) + " "
return transcript
def __eq__(self,other):
return self.courses == other.courses
  
def add_course(self, course):
for crs in self.courses:
if course == crs:
raise CourseError("duplicate course number '" + course.number + "'")
self.courses.append(course)

def course_by_number(self, number):
for course in self.courses:
if course.number == number:
return course
return None

def course_by_grade(self, grade):
grade_list = []
for course in self.courses:
if course.grade == grade:
grade_list.append(course)
return grade_list
def total_passing_credit(self):
total_hours = 0
for course in self.courses:
if course.is_passing():
total_hours += course.credit
return total_hours

c1 = Course("CS112",4,"A")
print(c1.is_passing())
c2 = Course("ENGH101",3,"B")
print (c1==c2)
c3 = Course("MATH113",4,"IP")
t = Transcript()
print(str(t))

t.add_course(c1)
t.add_course(c2)
t.add_course(c3)
print(str(t))

t.add_course(Course("GAME101",3,"A"))
t.course_by_number("CS112")
print(t.course_by_number("CS112"))
t.course_by_number("CS114")
print(t.course_by_number("CS114"))
ans = t.course_by_grade("A")
print(len(ans))

c = Course("CS101",2,"Y") # this should raise a CourseError

# pastebin code link: https://pastebin.com/zaKDAAKs

Now about the error you are getting, you test is expecting a int and its getting a None,

But this really can't be solved without your providing your full tester class. Put your tester in some online source and share link in comment and I will fix your errors so that all test pass (assuming tester is something instructor provided)