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

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2014.11.11
系所別:
年級:
學號:
姓名:
考試時間 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).
    # Function Definition & Invocation
    def sumN(N):
        a = 0
        for i in range(N):
            a = a + (i+1)
        return a

    def sumNCube(N):
        a = 0
        for i in range(N):
            a = a + ((i+1)**3)
        return a

    print(sumN(5), sumNCube(5))

  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).
    # Function Parameters and Return Values
    def stars(n):
        for i in range(n):
            print('*', end='')
        print()
        return n

    print( stars(3) + stars(5) )

  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).
    # Pass by Value
    def max(a, b, c):
        a = b
        a = c
        print("The maximum value is", a)
        return a

    def main():
        x, y, z = 5, 4, 8
        print( max(x, y, z ) )
        print( x, y, z )

    main()