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

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2014.10.21
系所別:
年級:
學號:
姓名:
考試時間 15: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).
    # Date Conversion
    inputStr = "2014/10/21"
    year, month, day = inputStr.split("/")
    print("今年是民國", year - 1911, "年")



  2. (10%) Suppose that you created a file "hello.txt" using "nano" with the following contents:
    123456789012
    Hello, NCNU.
    Hello
    NCNU
    What will be the output by running the following code?
    # Word, line, and character count
    Infile = open("hello.txt", "r")
    s = Infile.read()
    print( len(s) )
    Infile.close()


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

    for i in range(1, 5):
        s = "{0:>" + str(i) + "}"
        print(i, s, s.format("*") )


  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).
    # String Justification
    for i in range(1,10, 2):
        print( "{0:^9}".format( '*' * i ) )