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

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2013.11.12
系所別:
年級:
學號:
姓名:
考試時間 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 Invoking
    def sumN(n):
        sum = 0
        for i in range(n+1):
            sum = sum + i
        print(sum)

    def sumNCube(n):
        sum = 0
        for i in range(n+1):
            sum = sum + i**3
        print(sum)

    def main():
        print( sumN(5), sumNCube(5) )

    main()



  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).
    # Pass by value
    def main():
        aList = [1, 2, 3]
        print(aList)
        append(aList, 4)
        print(aList)

    def append(s, n):
        s = s + [n]
        print("This updated list is", s)

    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).
    # Modifying a list in a function

    def main():
        aList = [1, 2, 3]
        print(aList)
        double(aList)
        print(aList)

    def double(s):
        for i in range(len(s)):
            s[i] = s[i] * 2
        print("This updated list is", s)

    main()