CMU 15-112 Spring 2019: Fundamentals of Programming and Computer Science
Check 8.1


  1. Check 8.1
    A vehicle class might have these three properties: numberOfWheels, hasEngine, and color. Think of another class and come up with three different properties! Each of these properties should be determined by one of three inputs. Define the class and its __init__ method, then create two different objects called thing1 and thing2 and print their properties. We have started this for you; just replace each "xxx" as needed, and be creative!
    class xxx(object): def __init__(self, xxx, xxx, xxx): self.xxx = xxx self.xxx = xxx self.xxx = xxx thing1 = xxx(xxx, xxx, xxx) #Note that we don't provide self as input thing2 = xxx(xxx, xxx, xxx) print(thing1.xxx, thing1.xxx, thing1.xxx) print(thing2.xxx, thing2.xxx, thing2.xxx) import sys def set_certificate(certificate_div_id, certificate): document[certificate_div_id].textContent = certificate def get_student_code(student_code_div_id): raw_student_code = document[student_code_div_id].textContent return window.patchCodeToCheckTimeout(raw_student_code, 'check_timeout();'); class captureIO: def __init__(self): self.captured = [] def get_output(self): out = "" for c in self.captured: out += str(c) return out def write(self, data): self.captured.append(data) def flush(self): pass def make_certificate(student_code_div_id, certificate_div_id): student_code = get_student_code(student_code_div_id) certificate = [] try: capture = captureIO() sys.stdout = capture sys.stderr = capture exec(student_code) output = student_code.count("xxx") certificate.append((output, type(output))) except: pass set_certificate(certificate_div_id, str(certificate))

  2. Back to notes