私は、money == 100の場合は配列内の項目に1を加え、そうでない場合は別の項目に1を加えることで、Pythonで三項演算を実行しようとしています。しかし、私は無効な構文エラーを取得し続けます。整数を追加するPython三項演算子
bills[2] += 1 if money == 100 else bills[1] += 1
^
SyntaxError: invalid syntax
ここにコードがあります。
def tickets(people):
change =0
bills = [0,0,0]
for i,money in enumerate(people):
if money == 25:
change += 25
bills[0] += 1
str = "This is the %d th person with %d money" % (i,money)
print(str)
else:
bills[2] += 1 if money == 100 else bills[1] += 1
change -= (money -25)
str = "This is the %d th person with %d money" % (i,money)
print(str)
print("change is %d" % change)
if change < 0:
return "NO"
else:
return "YES"
else部分の 'bill [2]'に 'bills [1] + 1'を追加しますか? – letmutx