Differences between revisions 4 and 5
Revision 4 as of 2019-10-09 14:58:26
Size: 2302
Comment:
Revision 5 as of 2019-10-09 17:18:19
Size: 2306
Comment:
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
#acl AdminGroup:read,write,delete,revert,admin TadashiIijima:read,write,delete,revert,admin IijimaStaffGroup: IijimaGroup: IijimaObogGroup: GuestGroup: Known: All: #acl AdminGroup:read,write,delete,revert,admin TadashiIijima:read,write,delete,revert,admin IijimaStaffGroup: IijimaGroup: IijimaObogGroup: GuestGroup: Known: All:read

[ edit ]

  • 例題ファイルとしては,コメントを付け加えた,下記を配布します.
    • コメントはもう少し増えるかもしれません.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ==============================================================================
# * Copyright (c) 2018 IIJIMA, Tadashi
# *       (IIJIMA Laboratory, Dept. of Science and Technology, Keio University).
# ==============================================================================
# ソフトウェア工学[02] 例題[02]-(003a)  Ex_02_003a_triangle_number.py
# Ex(Example) 02-003a: 【関数定義】 n番目の三角数を求める関数を定義する. 
#                               n番目の三角数は,1からnまでの総和と等しい. 
#        2018-10-03 飯島 正 (iijima@ae.keio.ac.jp)
# ==============================================================================
# ===== 【関数定義】 n番目の三角数 =====
def triangle_number( n ):
    return( int( n * (n + 1) / 2 ) )
# ==============================================================================
# ===== 【関数定義】 1からnまでの総和 =====
def sum_of_one_to_n( n ):
    sum = 0
    for i in range( 1, n+1 ):
        sum += i
    return( sum )
# ==============================================================================
# ===== 【メイン・プログラム】 =====
# ----- オープニングメッセージ -----
print( "n番目の三角数を求めます(1~nの総和と比較します): " )

# ----- パラメータの入力 -----
n = int( input( "正の整数を入力してください>>> " ) );

# ----- 結果の表示 ----
print( "    ",    n, "番目の三角数は ", triangle_number( n ) )
print( "    1 ~", n, "までの総和は ",   sum_of_one_to_n( n ) )
# ==============================================================================

SoftEng: Python/Prog/Example/02/Ex_003a/Distribution (last edited 2019-10-09 17:18:19 by TadashiIijima)