と私のpythonに新しいですし、私は完全に理解して学んでいたが、私はこの部分に引っかかってしまった{TypeError例外:サポートされていないオペランドのタイプ(複数可)+用:「int型」と「STR」}入力
money = input("Enter the expenses: ")
addup = money.split()
total = sum(addup)
print("Total: ", total)
と私のpythonに新しいですし、私は完全に理解して学んでいたが、私はこの部分に引っかかってしまった{TypeError例外:サポートされていないオペランドのタイプ(複数可)+用:「int型」と「STR」}入力
money = input("Enter the expenses: ")
addup = money.split()
total = sum(addup)
print("Total: ", total)
を動作する可能性があります:
money=map(float,input().split()) #could have use int as well if input was a sequence of integers
total=sum(money)
print("Total:",total)
あなたもこれを行うことができます:python入力で
Total=sum(map(float,input().split())) #could have use int as well if input was a sequence of integers
print("Total:",total)
をデフォルトでは、文字列として扱われますタイプキャストする必要があります
int(input("enter the expenses should work: "))
か、それはあなたが必要とするすべての型キャストしているか、一般的に
float(input("enter the expenses should work: "))
をフロートであれば、あなたの入力は
map(int,input().split()) #can use float here as well
は、Python 2.xのマップで作成するか番号のリストがある場合python 3.xではジェネレータを作成します。
彼らは何か浮動小説なら何ですか? – SuperStew
私は意図した入力が '12 34 56 78'のようなものだと疑っています –
@SuperStewええ、投稿を編集しました。 – Demonking28
あなたは何をしっかりつかんでいますか? – glibdud
ええ、私たちはあなたがエラーを受け取る行番号が必要です - それはsum()関数ですか?文字列を整数に追加しようとしていますか? –
@オスカー私はあなたの問題に応じて私の答えを編集しました。私はあなたが正しい答えとして役立つマークそれを見つけるf :) – Demonking28