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

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2014.10.14
系所別:
年級:
學號:
姓名:
考試時間 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).
    # Print Out a String by the Reverse Order
    alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    n = len(alphabet)
    for i in range(n // 2):
        print(alphabet[n - 1 - i], end='')
    print()



  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).
    # Indexing and Slicing
    def main():
        first = "Angelina"
        last  = "Jolie"
        print(first[1] + last[:1])
    main()


  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
    # ord('A')=65, ord('a')=97


    message  = "MIT"
    for ch in message:
        print( chr( ord(ch) + 35 ), end='' )
    print()


  4. (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).
    # Dice Rolling
    count = [ 0, 1, 1, 2, 4, 2 ]
    for n in [1, 2, 2, 3, 5, 3 ]:
        count[n-1] = count[n-1] + 1

    for i in range(6):
        print( i+1 , count[i] )