sum関数によって、数字が入ったリストを合計して、その後平均値を求めたいプログラムを書いています。
実際に書いたプログラムは
from random import choice from string import digits random_num = "".join([choice(digits) for i in range(7)]) list_random = list(random_num) print(list_random) list_r = int(list_random) s = sum(list_r) l = len(list_l) f = s/ l print(f)
です。
このlist_r = int(list_random)の箇所で以下のエラーメッセージが出ます。
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
リスト内の数字が文字列型のため、intによって数値に変えないとsum関数が使えないと思い、以上のようなプログラムを書いたのですが、どこが間違っているのでしょうか。教えてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/20 10:43
2018/07/20 10:44
2018/07/20 10:47