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

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2015.10.20
系所別:
年級:
學號:
姓名:
考試時間 14:10-15: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).
    # Simultaneous Assignment
    a, b, c = 1, 2, 3
    for i in range(10):
        a, b, c = b, c, a
    print(a, b, c)


  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).
    # String Length
    s = "HELLO\n\nNCNU\n"
    print(len(s), ord(s[-1]))


  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).
    # String Slicing
    N = 5
    s = " "*(N-1)+"+"+" "*(N-1)
    for i in range(N-1):
        print( s[ i : i+N ] )
    for i in range(N-1, -1, -1):
        print( s[ i : i+N ] )



  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).
    # Indexing means to retrieve a character from a string with its index number
    aList = ["###", "--#", "###", "#--"]
    for i in range(8):
        print( aList[i % 4] )



  5. (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).
    # Dynamically create a template string

    for i in range(8):
        s = "{0:" + "><"[i % 2] + "3}"
        print( s.format("#") )