#Indicamos que acepta variables int and float y el tipo de dato de salida
#We do not need to store the result in memory
#Indicamos que acepta variables int and float y el tipo de dato de salida def other_angle(a: int | float, b: int | float) -> int | float: return 180 - (a + b) #We do not need to store the result in memory
def other_angle(a, b):req_angle = 180 - (a + b)return req_angle- #Indicamos que acepta variables int and float y el tipo de dato de salida
- def other_angle(a: int | float, b: int | float) -> int | float:
- return 180 - (a + b) #We do not need to store the result in memory
import codewars_test as test @test.describe("tests") def fixed_tests(): @test.it('test cases') def basic_test_cases(): test.assert_equals(other_angle(30, 60), 90) test.assert_equals(other_angle(60, 60), 60) test.assert_equals(other_angle(43, 78), 59) test.assert_equals(other_angle(10, 20), 150) test.assert_equals(other_angle(110, 30), 40) test.assert_equals(other_angle(100, 40), 40)
- import codewars_test as test
- @test.describe("tests")
- def fixed_tests():
- @test.it('test cases')
- def basic_test_cases():
- test.assert_equals(other_angle(30, 60), 90)
- test.assert_equals(other_angle(60, 60), 60)
- test.assert_equals(other_angle(43, 78), 59)
- test.assert_equals(other_angle(10, 20), 150)
- test.assert_equals(other_angle(110, 30), 40)
- test.assert_equals(other_angle(100, 40), 40)
dumbRockPaperScissors(player1:str, player2:str) -> str:
A la hora del uso diario, agregar información de las variables que recibe la función y su salida. Es una de las mejores prácticas que podemos realizar
Rock, Paper, Scissors -> Los nombres de las variables expresan correctamente su contenido. Al ser tan simple, podemos realizar las declaraciónes en una línea dando igual legibilidad, reduciendo líneas de código y dando mejor apariencia al código.
def dumbRockPaperScissors(player1:str, player2:str) -> str: Rock, Paper, Scissors = {"Paper"}, {"Scissors"}, {"Rock"} if player1 == player2: return "Draw" #we use 'eval' once for two results and implicit return return "Player 1 wins" if player1 in eval(player2) else "Player 2 wins" #This is the same code in one line #return "Draw" if player1 == player2 else "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"
def dumbRockPaperScissors(player1, player2):Rock = {"Paper"}Paper = {"Scissors"}Scissors = {"Rock"}if player1 in eval(player2):return "Player 1 wins"elif player2 in eval(player1):return "Player 2 wins"else:- def dumbRockPaperScissors(player1:str, player2:str) -> str:
- Rock, Paper, Scissors = {"Paper"}, {"Scissors"}, {"Rock"}
- if player1 == player2:
- return "Draw"
- #we use 'eval' once for two results and implicit return
- return "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"
- #This is the same code in one line
- #return "Draw" if player1 == player2 else "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"