0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python学習ノート_006

Posted at

第4章のサンプルコードは下記のようです。

  • ポイント
  • リストの長さはlen()で計算して、forループにインデックスの上限値として使える
  • printにコンマで区切った複数の値の間に1スペースがあるため、それを回避する方法は文字列の連結で1つ文字列として出力する
sample04.py
scores = [60, 50, 60, 58, 54, 54,
          58, 50, 52, 54, 48, 69,
          34, 55, 51, 52, 44, 51,
          69, 64, 66, 55, 52, 61,
          46, 31, 57, 52, 44, 18,
          41, 53, 55, 61, 51, 44]

length = len(scores)

for i in range(length):
    print("テストの案 #" + str(i),"のscore:",scores[i])

high_score = max(scores)
max_list = []
for i in range(length):
    if scores[i] == high_score:
        max_list.append(i)
        
print("テストの総数:",length)
print("最高の点数:",max(scores))
print("最大値のインデックス:",max_list)
  • 出力結果
    サンプル4の出力結果の一部
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?