國立暨南國際大學 102 學年度第一學期小考試卷

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2013.10.29
系所別:
年級:
學號:
姓名:
考試時間 14:10-14:20
  1. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    # String slicing
    first = "John"
    last  = "Rambo"
    username = first[0] + last[:7]
    print(username, username.lower(), sep='\n' )



  2. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    # Splitting a list
    list1 = "ABC,ABC,ABC".split(",")
    list2 = "ABCABCABC".split("B")
    print( len(list1), list1[1] )
    print( len(list2), list2[2] )



  3. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    # Caesar Cipher
    # chr('A') == 65
    # chr('Z') == 90

    plaintext  = "BOX"
    ciphertext = ""
    key = 3

    for ch in plaintext:
        c = chr( ( ord(ch) - 65 + key ) % 26 + 65 )
        ciphertext = ciphertext + c
    print(ciphertext)