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


  1. Check 3.5
    Write a function called replaceArrows(s) which takes in a string s, replaces all instances of "<<" in the string with a space, and returns the result.
    def replaceArrows(s): return 42 def testReplaceArrows(): print("Testing replaceArrows...", end="") assert(replaceArrows("You<<did<<it!")=="You did it!") assert(replaceArrows("Don't<<replace<<single '<'s!")=="Don't replace single '<'s!") print("passed!") testReplaceArrows() 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: execCapture = captureIO() sys.stdout = execCapture sys.stderr = execCapture exec(student_code) for test in ['n<<mcuu<<<<gk', '<<hxxi<<p<<ci<<f<<ht<<', 'xc<<r', '<<<<<<vrw<<synsq<<jckl', 'tgc<<u<<<<tzl<<', '<<g<<v', '<<fo<<<<u<<<<k<<ni<<', '<<gv<<<<b', 'ujcr<<<<<<laseenxf<<', 'wnxvk<<qp<<bpz<<z<<<<cdez', '<<bvk<<cuh<<jp<<abnbswh', '<<<<<<m', 'jtuqq<<ckwu<<<<i<<<<', 'okqajnmg<<k<<qwgzn<<e', '<<a<<a<<s<<rmwbczrcg<<xuk', 'v<<h<<<<t<<<<h<<', '<<<<f<<oc<<q<<q<<kbin<<', 'hq<<laum<<n<<<<mh<<', 'vmv<<elfaa<<<<m<<b<<<<r', 'wna']: output = replaceArrows(test) certificate.append((output, type(output))) except: pass set_certificate(certificate_div_id, str(certificate))

  2. Back to notes