0

Rock, Paper, Scissors variable bot has default value Variable Alex, has values that are passed to main.py When I call method comparison I get an error Method comparisons from secrets import choice from variants import Variants

Player.py

class Player:
    name = '',
    choice = ''

    def __init__(self, choise = 'ROCK', name = 'bot'):
        self.name = name
        self.choice = choice
    
    def whoWins(self, bot, alex):
        if bot.choice > alex.choice:
            print('bot, winner')
        if bot.choice < alex.choice:
            print('Alex, winner')
        if bot.choice == alex.choice:
            print('draw')

main.py

from variants import Variants
from player import Player

bot = Player()
alex = Player(Variants.ROCK, "Alex")
print(bot.whoWins(bot, alex))

variants.py

from enum import Enum

class Variants(Enum):
    ROCK = 1,
    PAPER = 2,
    SCISSORS = 3
9RoxXx
  • 21
  • 6

2 Answers2

1

The problem with Variants is the trailing comma after ROCK and PAPER -- the comma turns the value into a tuple, so

  • ROCK.value == (1, )
  • PAPER.value == (2, )
  • SCISSORS.value == 3
Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
  • it seems to me that the problem is not there, the problem is in the WhoWins method, the methods cannot be compared, but I'm scratching my head how to designate them so that the program knows exactly who won – 9RoxXx Sep 23 '22 at 04:02
  • `if bot.choice > alex.choice: TypeError: '>' not supported between instances of 'method' and 'method'` – 9RoxXx Sep 23 '22 at 04:04
  • @9RoxXx: It may not be the whole problem, but it's definitely a problem. – Ethan Furman Sep 23 '22 at 17:16
1

Answer: I had to modify the comparison of methods, I did it like this: also main.po remained the same:

> from variants import Variants from player import Player
> 
> bot = Player() alex = Player(Variants.ROCK, "Alex")
> print(bot.whoWins(bot, alex))

variants.py remained the same

from enum import Enum

class Variants(Enum):
    ROCK = 1
    PAPER = 2
    SCISSORS = 3

Player.py

from secrets import choice
from variants import Variants

class Player:
    name = '',
    choice = ''

    def __init__(self, choice = Variants.ROCK,  name = 'bot'):
        self.name = name
        self.choice = choice
    
    def whoWins(self, bot, alex):
        if (bot.choice == Variants.ROCK and alex.choice == Variants.PAPER):
            print('Alex, win!')
        if (bot.choice == Variants.PAPER and alex.choice == Variants.ROCK):
            print('Alex, win!')
        if (bot.choice == Variants.SCISSORS and alex.choice == Variants.SCISSORS):
            print('draw')
        if (bot.choice == Variants.ROCK and alex.choice == Variants.ROCK):
            print('draw!')
        if (bot.choice == Variants.ROCK and alex.choice == Variants.SCISSORS):
            print('Bot, win')
        if (bot.choice == Variants.SCISSORS and alex.choice == Variants.PAPER):
            print('Bot, win')
        if (bot.choice == Variants.SCISSORS and alex.choice == Variants.ROCK):
            print('Alex, win!')
        if (bot.choice == Variants.PAPER and alex.choice == Variants.SCISSORS):
            print('Alex, win!')
        elif (bot.choice == Variants.SCISSORS and alex.choice == Variants.SCISSORS):
            print('draw!')

if bot.choice > alex.choice: TypeError: '>' not supported between instances of 'method' and 'method' - The error is gone

All, is ok!

PS C:\Users\user\2> python.exe main.py
Alex, win!
PS PS C:\Users\user\2>
9RoxXx
  • 21
  • 6