[Solved] convert js function to Python [closed]
It’s more straightforward than you think: def getCardinalDirection(angle): directions = [‘↑ North’, ‘↗ North East’, ‘→ East’, ‘↘ South East’, ‘↓ South’, ‘↙ South West’, ‘← West’, ‘↖ North West’] return directions[round(angle / 45) % 8] # round() is a built-in function Example output: >>> getCardinalDirection(50) ‘↗ North East’ >>> getCardinalDirection(220) ‘↙ South West’ >>> … Read more