Ad

#Indicamos que acepta variables int and float y el tipo de dato de salida

#We do not need to store the result in memory

Code
Diff
  • #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
Sets

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.

Code
Diff
  • 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"