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


  1. Check 4.6
    Go browse through the page with the list of list methods linked under "More list methods", find one that you think is interesting (it might be one you've seen in the notes already), and try it out in the following code box. Press submit when you're done.
    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 has_list_keywords(code): keyword_set = {'append', 'extend', 'insert', 'remove', 'pop', 'clear', 'index', 'count', 'sort', 'reverse', 'copy', 'del', '*='} codeSet = set() for key in keyword_set: if key in code: return "Correct Code" if "[" in code and "]" in code: return "Correct Code" return "No Keyword Found" def make_certificate(student_code_div_id, certificate_div_id): student_code = get_student_code(student_code_div_id) certificate = [] try: execCapture = captureIO() sys.stdout = execCapture sys.stderr = execCapture exec(student_code) output = has_list_keywords(student_code) certificate.append((output, type(output))) except: set_certificate(certificate_div_id, "error") set_certificate(certificate_div_id, str(certificate))

  2. Back to notes