Can someone say why this doesn't work in Python? Is it simply invalid syntax or is there more to it?
arr[0] += 12 if am_or_pm == 'PM'
The error message:
File "solution.py", line 13
arr[0] += 12 if am_or_pm == 'PM'
^
SyntaxError: invalid syntax
This works:
if am_or_pm == 'PM': arr[0] += 12
arr[0] += 12 if am_or_pm == 'PM' else 0ifin a separate line, but the ternary conditional operator Ted suggested is fine as well.elsewould result in the "expression" having no defined value; e.g., what shouldprint('hi' if False)sensibly do (if we refrain from usingNoneeverywhere automatically, which is a design choice)?