Hey guys I working on some python homework which I am completely lost on.
I am trying to make a card game, most of it works fine except the my moveCard function it doesnt work and I dont know why.
Here is my code:
# Note: cards are represented as 2-character strings, e.g.,
# "2C", "9S", "QH", "TD", "AC"
from random import randint, shuffle
class DeckOfCards:
def __init__(self):
"""Initializes a new deck of cards."""
ranks = "23456789TJQKA"
suits = "CDHS"
self.cards = [r+s for r in ranks for s in suits]
def shuffle(self):
"""Shuffles the cards into a random order."""
shuffle(self.cards)
def dealCard(self):
"""Removes the top/last card in the deck & returns it."""
if self.numCards() > 0:
return self.cards.pop()
else:
return ""
def addCard(self, card):
"""Adds the specified card to the bottom/front of the deck."""
self.cards.insert(0, card)
def numCards(self):
"""Returns the number of cards remaining in the deck."""
return len(self.cards)
def __str__(self):
"""Returns the string representation of the deck."""
return ' '.join(self.cards)
#########
class RowOfCards:
def __init__(self):
"""Initializes an empty row (list) of cards."""
self.cards = []
def addAtEnd(self, card):
"""Adds the specified card to the end of the row (list)."""
self.cards.append(card)
def moveCard(self, card, numSpots):
"""Moves the specified card numSpots to the left."""
self.cards.index(card)
(i for i in list if card == self)
print i
self.cards.remove(i)
self.cards.insert(i - numSpots, card)
def numCards(self):
"""Returns the number of cards in the row (list)."""
return len.self.cards
def __str__(self):
"""Returns the string representation of the deck (list)."""
return ' '.join(self.cards)