前提・実現したいこと
pythonで与えられたリストの最大の数値と最少の数値の差に対し、リストの最後尾の数値を掛けた値を返す計算をしています。
number = [] の時だけ0を出力させたいです。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "print_string.py", line 20, in <module> result = check_sample(number) File "print_string.py", line 5, in check_sample a = max(number) ValueError: max() arg is an empty sequence
該当のソースコード
python
1def check_sample(number): 2 a = max(number) 3 b = min(number) 4 c = a- b 5 d = number[-1] 6 e = d * c 7 8 return e 9 10 11 12number = [] 13 14if number == []: 15 print(0) 16 17result = check_sample(number) 18print(result)
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/03 04:04
2019/06/03 04:19