-2

Using python 3.7.3. all documentation is points to this being the correct way to do a switch statement in python. Not sure why it's not working. Am I supposed to import match? syntax error below.

    match player:
               ^
def evaluate(player, ai):
    match player:
        case Choice.rock:
            if ai == Choice.rock:
                return "draw"
            elif ai == Choice.scissors:
                return "player wins"
            elif ai == Choice.paper:
                return "ai wins"
        case Choice.paper:
            if ai == Choice.rock:
                return "player wins"
            elif ai == Choice.scissors:
                return "ai wins"
            elif ai == Choice.paper:
                return "draw" 
        case Choice.scissors:
            if ai == Choice.rock:
                return "ai wins"
            elif ai == Choice.scissors:
                return "draw"
            elif ai == Choice.paper:
                return "player wins"
Chris_Rands
  • 38,994
  • 14
  • 83
  • 119
Sitruc s
  • 15
  • 1

1 Answers1

3

match requires python version >= 3.10, see what's new

Chris_Rands
  • 38,994
  • 14
  • 83
  • 119