Differences between revisions 2 and 3
Revision 2 as of 2019-03-28 15:21:16
Size: 587
Comment:
Revision 3 as of 2019-03-28 15:22:28
Size: 2722
Comment:
Deletions are marked like this. Additions are marked like this.
Line 27: Line 27:
=== 解答例1 () === === 解答例1 (exam_04_03a_transform_text.py) ===
Line 30: Line 30:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ==============================================================================
# * Copyright (c) 2018 IIJIMA, Tadashi
# * (IIJIMA Laboratory, Dept. of Science and Technology, Keio University).
# ==============================================================================
# ソフトウェア工学 期末試験 (追試) exam_04_03a_transform_text.py
# Exam 04-03: 英文のファイル内容を大文字に変換し,逆順にファイルへ出力する
# 2019-02-06 飯島 正 (iijima@ae.keio.ac.jp)
# ==============================================================================
import sys
# ==============================================================================
# ===== 【関数】 =====
def read_file_contents(file_name):
    lines = []
    try:
        with open(file_name) as f:
            lines = f.readlines()
    except FileNotFoundError:
        print( "エラー:ファイルがない" )
        sys.exit()
    return( lines )
# ==============================================================================
# ===== 【関数】 =====
def transform_to_uppercase(lines):
    upper_lines = []
    for line in lines:
        upper_lines.append( line.upper() )
    return( upper_lines)
# ==============================================================================
# ===== 【関数】 =====
def output_uppercase_lines_reverse_order( file_name, lines ):
Line 31: Line 63:
    # ----- -----
    upper_lines = transform_to_uppercase(lines)

    # ----- -----
    upper_lines.reverse()
    print(upper_lines)

    # ----- -----
    with open(file_name, "w") as f:
        f.writelines( upper_lines )

# ==============================================================================
# ===== 【メイン・プログラム】 =====

# ----- -----
lines = read_file_contents("input_data.txt")

# ----- -----
print(lines)

# ----- -----
output_uppercase_lines_reverse_order( "output_data.txt", lines )

# ==============================================================================


授業-ソフトウェア工学 > 2018年度 > 試験 > 期末試験 (追試) > 期末試験 (追試) 問題03


授業-2018年度-ソフトウェア工学-期末試験 (追試) 問題03

問題03:

*

(公開)



問題 03:

[ edit]


問題

[ edit]



解答例1 (exam_04_03a_transform_text.py)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ==============================================================================
# * Copyright (c) 2018 IIJIMA, Tadashi
# *       (IIJIMA Laboratory, Dept. of Science and Technology, Keio University).
# ==============================================================================
# ソフトウェア工学 期末試験 (追試) exam_04_03a_transform_text.py
# Exam 04-03: 英文のファイル内容を大文字に変換し,逆順にファイルへ出力する
#        2019-02-06 飯島 正 (iijima@ae.keio.ac.jp)
# ==============================================================================
import sys
# ==============================================================================
# ===== 【関数】 =====
def read_file_contents(file_name):
    lines = []
    try:
        with open(file_name) as f:
            lines = f.readlines()
    except FileNotFoundError:
        print( "エラー:ファイルがない" )
        sys.exit()
    return( lines )
# ==============================================================================
# ===== 【関数】 =====
def transform_to_uppercase(lines):
    upper_lines = []
    for line in lines:
        upper_lines.append( line.upper() )
    return( upper_lines)
# ==============================================================================
# ===== 【関数】 =====
def output_uppercase_lines_reverse_order( file_name, lines ):

    # -----  -----
    upper_lines = transform_to_uppercase(lines)

    # -----  -----
    upper_lines.reverse()
    print(upper_lines)

    # -----  -----
    with open(file_name, "w") as f:
        f.writelines( upper_lines )

# ==============================================================================
# ===== 【メイン・プログラム】 =====

# -----  -----
lines = read_file_contents("input_data.txt")

# -----  -----
print(lines)

# -----  -----
output_uppercase_lines_reverse_order( "output_data.txt", lines )

# ==============================================================================


SoftEng: 2018/Exam/04/03/IndexPage (last edited 2019-03-28 15:22:28 by TadashiIijima)