如何将列表对象转换为多个int

时间:2019-04-13 22:16:32

标签: python python-3.x

我们的作业要求我们制作一个游戏,该游戏对以1-20 +石头​​,纸张,剪刀+硬币投掷的值出现的纸牌值进行排序。像这样:

14个纸头

剪刀尾巴9个

我们必须列出其中的30种,并按值(前导数字)或手(石头,纸,剪刀)进行排序。我们还必须能够选择特定的卡,并查看它是否在卡座中。我有办法做到这一点,但是我目前的方法是将列表中的每个值作为一个完整的字符串存储。

import random
class Card:
    def __init__(self, id=0):
        self.id = id
        self.vals = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
                     "19", "20"]
        self.hands = ["Rock", "Paper", "Scissors"]
        self.coins = ["Heads", "Tails"]
        k = 0
    for v in self.vals:
        for h in self.hands:
            for c in self.coins:
                if k == self.id:
                    self.vals = v
                    self.hands = h
                    self.coins = c
                k += 1

def getVals(self):
    return self.vals

def getHands(self):
    return self.hands

def getCoins(self):
    return self.coins

def setVals(self, vals):
    self.vals = vals

def setHands(self, hands):
    self.hands = hands

def setCoins(self, coins):
    self.coins = coins

def __str__(self):
    return self.vals + " of " + self.hands + " " + self.coins

class Deck:
    def __init__(self):
        self.vals = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
                     "19", "20"]
        self.hands = ["Rock", "Paper", "Scissors"]
        self.coins = ["Heads", "Tails"]
        self.deck = []
        for i in range(len(self.vals) * len(self.hands) * len(self.coins)):
            self.deck.append(Card(i))

def getDeck(self):
    return self.deck

def getVals(self):
    return self.vals

def getHands(self):
    return self.hands

def getCoins(self):
    return self.coins

def setDeck(self, deck):
    self.deck = deck

def setVals(self, vals):
    self.vals = vals

def setHands(self, hands):
    self.hands = hands

def setCoins(self, coins):
    self.coins = coins

def shuffle(self):
    random.shuffle(self.deck)

def returnDeck(self, num):
    return self.deck[num]

我当前的想法是使每个值都可以被不同的数字整除,但是要做到这一点,我必须使对象的每个部分都具有不同的int。

1 个答案:

答案 0 :(得分:0)

我认为您需要var classGrpCount = classDim.group().reduceCount(); var classGrpSum = classDim.group().reduceSum(function(d){ return d.donation}); //... compositechart.compose( [ dc.lineChart(compositechart) .group(classGrpCount) .valueAccessor(function(d){ return d.value} ), dc.barChart(compositechart) .group(classGrpSum) .valueAccessor(function(d){ return d.value}) .useRightYAxis(true) ]); 成为self.vals的列表。方法如下:

int