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?

プログラミング習得ログ : 書いたプログラムをもっと簡潔にしたい(が、タイムアップ)

Last updated at Posted at 2025-07-04

標準関数を使った書き方を教えてもらったので、アップデートしようと思い本日は以下にて途中でタイムアップ

学生の成績データを処理する関数

numbers = [10, 25, 30, 45, 60]
#要素数
#合計
#最大値
#最小値
#平均
#をそれぞれ出す
print(f'要素数:{len(numbers)}')
print(f'合計:{sum(numbers)}')
print(f'最大値:{max(numbers)}')
print(f'最小値:{min(numbers)}')
print(f'平均:{sum(numbers)/len(numbers)}')

#これがタプルになった時は?

scores = [("田中", 85), ("佐藤", 92), ("山田", 78), ("鈴木", 96), ("高橋", 81)]
def get_score(data):
    return data[1] #インデックス1(2番目)の要素を返す
student = ("田中", 85)
result = get_score(student)  # 85が返る

print(result)
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?