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


  1. Check 3.6
    Write a function called changeLowercase(s) which takes in a string s and replaces every lowercase letter with the character of the ord one less than it and returns the result. For example, "ABdDEF" changes to "ABcDEF" because the ord of "d" is 100, 100 - 1 is 99, and the ASCII character corresponding to 99 is "c".
    Note: Since there are no letters below a, an a will become a back tick. And that's okay!
    def changeLowercase(s): return 42 def testChangeLowercase(): print("Testing changeLowercase...", end="") assert(changeLowercase("ABdDEF")=="ABcDEF") assert(changeLowercase("Gsfbu!")=="Great!") assert(changeLowercase("dcb") == "cba") print("passed!") testChangeLowercase() 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 ['CeoFUHtCqxtYZPWaU1', 'Q1IMisD5GgIQFYn', 'ZNIKSIGCy', 'rj0WU8frVtDDCONla', 'OIhYcAU9MD', 'wPFe', 'ZhBifC3Hl5rmLgEkLsS', 'qXU', 'Yxb4IwEswVWsYezySP', '6DGejzl', '5cOa1p4imk2dG', 'nfAAs8GFVSe', 'tDWrLA', 'gg4j7LpTvHrlOJGc', '25Y4QfJVqNVPtMxf0F', 'T68Wfu4bMgBHKHprRkC', 'JDUsfZ0dCZPe', 'ec3OV', 'YL2EIUuL64tpa', 'ZX898qdqhL6jU3Rfy']: output = changeLowercase(test) certificate.append((output, type(output))) except: pass set_certificate(certificate_div_id, str(certificate))

  2. Back to notes