Python Recursion within Class

前端 未结 2 1557
闹比i
闹比i 2021-02-02 17:49

I just learn python today, and so am thinking about writing a code about recursion, naively. So how can we achieve the following in python?

class mine:
    def          


        
2条回答
  •  终归单人心
    2021-02-02 18:16

    This is a code example that actually works

    class Card():
        def __init__(self,cardsPlayedList,cardPosition):
            self.cardsPlayedList = cardsPlayedList
            self.cardPosition = cardPosition
        #    self.cardPosition
    
        def getNewCard(self,cardPosition):
            cardNum = 0
            cardInList = False
            
            cardNum = random.randint(1,len(cardList)-1)          # Get random card from List - 1 to 52 
            for x in self.cardsPlayedList:
                if(cardNum == x):
                    cardInList = True                            
    
            if(cardInList == False):
                self.cardsPlayedList.insert(self.cardPosition, cardNum)    # if card not already played then store in list
                return cardNum
            else:
                return self.getNewCard(cardPosition)   
    

提交回复
热议问题