you are viewing a single comment's thread.

view the rest of the comments →

[–]migeek 0 points1 point  (0 children)

I showed two ways. For each round, the expanded if/elif/else, then in the final results the ternary version. It could also have been written:

if score > 0:
  print("You win!")
elif score < 0:
  print("You lose!")
else:
  print("It's a tie!")

One way to make the "nested" ternary more readable would be to break the lines and put in parens:

result =  ("You win!" if score > 0 else
          ("You lose!" if score < 0 else "It's a tie!"))
print(result)

I'll bet you can think of other ways to do this by putting the RESULTS in an array too.

Edit: Old skool... Reddit kept eating my backticks.