You can do the test for whether it’s home or away in the query itself.
cursor.execute("""
SELECT
CASE WHEN robot_on_her_island = ? THEN 'Last_War_on_her_island'
ELSE 'Last_War_on_island_away'
END AS which_island,
points_war_home, points_war_away
FROM war
WHERE ? IN (robot_on_her_island, robot_on_island_away)
LIMIT 1""",
(select_robot_on_her_island, select_robot_on_her_island))
row = cursor.fetchone()
if row:
which_island, points_home, points_away = row
if which_island == 'Last_War_on_her_island':
print(which_island, points_home, points_away)
else:
# Swap the points when won on the away island
print(which_island, points_away, points_home)
BTW, if you just want one row, use fetchone()
rather than fetchall()[0]
.
26
solved Create condition that searches between two different WHEREs in the table