Mid-term Exam (1)
Introduction to Computer Science
NCNU CSIE

Date:  October 15, 2013
Time: 14:10-16:00
Open book; turn off computer & mobile phone

  1. (10%) Determine whether the following code has syntax erros or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).

    # print()
    for i in range(5):
        print(i, end=',')


  2. (10%) What will be the output of the following program?

    # int()
    for i in range(5):
        print( int( 2.3 * i + 0.5 ) )


  3. (10%) What will be the output of the following program?

    # Nested Loop
    n = 5
    for i in range(n):
        for j in range(i+1):
            print('*', end='')
        print()


  4. (10%) What will be the output of the following program?

    # Nested Loop
    n = 5
    for i in range(n):
        for j in range(n - 1 - i):
            print(end=' ')
        for j in range(i+1):
            print('*', end='')
        print()



  5. (10%) What will be the output of the following program?

    # Accumulator

    sum = 0
    for i in range(100):
        sum = sum + i
    print(sum)


  6. (10%) What will be the output of the following program?

    #
    Accumulator
    sum = 0
    for i in range(-100, 100, 2):
        sum = sum + i
    print(sum)

  7. (10%) Determine whether the following code has syntax erros or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).

    # Accumulator
    sum = 0
    for i in range(100, -100, -3):
        sum = sum + i
    print(sum)

  8. (10%) Determine whether the following code has syntax erros or
        not.  If it is correct, predict its output.  If it is
        incorrect, point out the
        mistake(s).

    # print()
    for i in range(5):
        print(i, sep=',')

  9. (10%) Determine whether the following code has syntax erros or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    # Accumulator
    n, m = 0, 0
    for i in range(10):
    for j in range(15):
    m = m + 1
    n = n + m
    print(n)

  10. (10%) Consider the following program.  What result will be shown on the screen after you run the program?  Please specify the coordinates of endpoints of each segment, or the coordinates of centers and boundaries.
    # clone() and move()
    x0, y0 = 100, 20
    dx, dy = 20, 20
    from graphics import *
    win = GraphWin("Midterm Exam (1)")
    for i in range(3):
    s1 = Line( Point(x0, y0), Point(x0 + dx, y0) )
    s2 = s1.clone()
    s2.move(0, dy)
    s3 = Line( Point(x0, y0), Point(x0, y0 + dy) )
    s4 = s3.clone()
    s3.move(dx, 0)
    s4.move(0, dy)
    s1.draw(win)
    s2.draw(win)
    s3.draw(win)
    s4.draw(win)
    y0 = y0 + 2 * dy