我试图在python中进行三元运算,如果money == 100,则在数组中的项目中添加1,如果不是,则在另一个项目中添加1.但我继续得到无效的语法错误.
bills[2] += 1 if money == 100 else bills[1] += 1
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
这是代码.
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 …Run Code Online (Sandbox Code Playgroud)