【问题标题】:python methods in comparison比较的python方法
【发布时间】:2022-09-23 01:43:34
【问题描述】:

Rock, Paper, Scissors 变量 bot 具有默认值 变量 Alex,具有传递给 main.py 的值 当我调用方法比较时出现错误 方法比较 从秘密进口选择 从变体导入变体

播放器.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\')

主文件

from variants import Variants
from player import Player

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

变体.py

from enum import Enum

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

    标签: methods enums pytorch


    【解决方案1】:

    Variants 的问题是ROCKPAPER 后面的逗号——逗号将值变成tuple,所以

    • ROCK.value == (1, )
    • PAPER.value == (2, )
    • SCISSORS.value == 3

    【讨论】:

      猜你喜欢
      • 2018-05-27
      • 2017-03-10
      • 1970-01-01
      • 2021-08-24
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      • 2018-06-30
      • 1970-01-01
      相关资源
      最近更新 更多