语法无效,我不知道为什么

需要帮助的人

这是我的代码:

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 条件为真时添加4else 添加9

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章