Differences between revisions 1 and 2
Revision 1 as of 2019-03-28 13:49:14
Size: 603
Comment:
Revision 2 as of 2019-03-28 14:37:41
Size: 2604
Comment:
Deletions are marked like this. Additions are marked like this.
Line 24: Line 24:
Line 25: Line 26:
=== 関数 === === 解答例1 (exam_03_04a_phone_number_list.py) ===


{{{#!highlight python numbers=off
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ==============================================================================
# * Copyright (c) 2018 IIJIMA, Tadashi
# * (IIJIMA Laboratory, Dept. of Science and Technology, Keio University).
# ==============================================================================
# ソフトウェア工学 期末試験 exam_03_04a_phone_number_list.py
# Exam 03-04: 氏名から電話番号(文字列でよい)を検索する電話帳
# 2019-01-16 飯島 正 (iijima@ae.keio.ac.jp)
# ==============================================================================
import sys
# ==============================================================================
# ===== 【関数定義】 電話番号を登録する =====
def add_phone_number( name, number, phone_book ):
    phone_book[name] = number
# ==============================================================================
# ===== 【関数定義】電話番号を検索する =====
def search_phone_number( name, phone_book ):
    number = ""
    try:
        number = phone_book[name]
    except KeyError:
        number = "未登録"
    return( number )
# ==============================================================================
# ==============================================================================
# ===== 【メイン・プログラム】 =====

# ----- 空の電話帳を作る -----
phone_book = {}

# ----- 電話番号を登録する -----
add_phone_number( "aaa", "090-0000-1111", phone_book )
add_phone_number( "bbb", "090-0000-2222", phone_book )
add_phone_number( "ccc", "090-0000-3333", phone_book )

# ----- 電話番号を検索する -----
print( "bbb", "さんの電話番号は", search_phone_number( "bbb", phone_book ) )
print( "ddd", "さんの電話番号は", search_phone_number( "ddd", phone_book ) )
Line 29: Line 72:


=== メイン ===
{{{#!highlight python numbers=off
# ==============================================================================


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


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

問題04:

*

(公開)



問題 04:

[ edit]


問題

[ edit]



解答例1 (exam_03_04a_phone_number_list.py)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ==============================================================================
# * Copyright (c) 2018 IIJIMA, Tadashi
# *       (IIJIMA Laboratory, Dept. of Science and Technology, Keio University).
# ==============================================================================
# ソフトウェア工学 期末試験 exam_03_04a_phone_number_list.py
# Exam 03-04: 氏名から電話番号(文字列でよい)を検索する電話帳
#        2019-01-16 飯島 正 (iijima@ae.keio.ac.jp)
# ==============================================================================
import sys
# ==============================================================================
# ===== 【関数定義】 電話番号を登録する =====
def add_phone_number( name, number, phone_book ):
    phone_book[name] = number
# ==============================================================================
# ===== 【関数定義】電話番号を検索する  =====
def search_phone_number( name, phone_book ):
    number = ""
    try:
        number = phone_book[name]
    except KeyError:
        number = "未登録"
    return( number )
# ==============================================================================
# ==============================================================================
# ===== 【メイン・プログラム】 =====

# ----- 空の電話帳を作る -----
phone_book = {}

# ----- 電話番号を登録する -----
add_phone_number( "aaa", "090-0000-1111", phone_book )
add_phone_number( "bbb", "090-0000-2222", phone_book )
add_phone_number( "ccc", "090-0000-3333", phone_book )

# ----- 電話番号を検索する -----
print( "bbb", "さんの電話番号は", search_phone_number( "bbb", phone_book ) )
print( "ddd", "さんの電話番号は", search_phone_number( "ddd", phone_book ) )



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


SoftEng: 2018/Exam/03/04/IndexPage (last edited 2019-03-28 14:37:41 by TadashiIijima)