Rock,Paper,Scissors变量bot具有默认值变量Alex,具有传递到www.example.com的值main.py当我调用方法比较时,我得到一个错误方法比较从secrets导入选择从变体导入变体
玩家.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')
主文件名.py
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
2条答案
按热度按时间waxmsbnn1#
Variants
的问题在于ROCK
和PAPER
后面的逗号--逗号将值转换为tuple
,因此ROCK.value == (1, )
PAPER.value == (2, )
SCISSORS.value == 3
5tmbdcev2#
答:我不得不修改比较的方法,我是这样做的:main.po也保持不变:
variants.py 保持不变
玩家.py
如果机器人选择〉亚历克斯选择:TypeError:“method”和“method”的示例之间不支持“〉”-错误已消失
"一切都好"