这是我的代码:
total = 0
s = "helloV"
for i in range(0, len(s)):
total += 4 if s[i] == "V" else (total += 9) # The line where I'm getting the syntax error.
我不确定为什么这段代码会给我一个语法错误。任何帮助,将不胜感激。
代码应该是这样的:
total = 0
s = "helloV"
for i in range(0, len(s)):
total += 4 if s[i] == "V" else 9
当 if 条件为真时添加4
else 添加9
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句