对于任何编码,我都是一个绝对的业余爱好者,但我一直在尝试使用Python创建一个顶级特朗普类型的程序。在下面的代码中,我创建了使用类添加到列表中的玩家卡。我现在正试图将列表(fullCardList)随机分成两个单独的列表,但有很多问题。 一旦名单被拆分,我的目标是比较每位球员的统计数据,但似乎不知道如何显示牌名/封顶/进球。我希望这是有道理的。有人能给我一些建议吗
class Player:
def __init__(self, name, caps, goals, trophies):
self.name = name
self.caps = caps
self.goals = goals
self.trophies = trophies
CardListOne = Player("Lionel Messi",102, 46, 26)
CardListTwo = Player("Ronaldo", 124, 55, 17)
CardListThree = Player("Mats Hummels", 39, 4, 8)
CardListFour = Player("Angel Di Maria", 65, 15, 10)
CardListFive = Player("Jason", 101,44,12)
CardsListSix = Player("Peter", 45,10,1)
fullCardList = [CardListOne.name, CardListOne.caps,CardListOne.goals,CardListOne.trophies],[CardListTwo.name,CardListTwo.caps,CardListTwo.goals,CardListTwo.trophies],[CardListThree.name, CardListThree.caps, CardListThree.goals, CardListThree.trophies], [CardListFour.name,CardListFour.caps,CardListFour.goals,CardListFour.trophies], [CardListFive.name,CardListFive.caps,CardListFive.goals,CardListFive.trophies]
global playersRandomSelection, computersRandomSelection
playersRandomSelection = []
playersRandomSelection = random.sample(fullCardList,3)
computersRandomSelection = []
computersRandomSelection = random.sample(fullCardList,3)
print("Players name selection: " + str(playersRandomSelection))
print("Computers random selection: " + str(computersRandomSelection))
您可以使用方法
vars()
:输出:
相关问题 更多 >
编程相关推荐