I got my code to work be the print out go's down on a angle is there anyway to stop this from happing. P.S sorry for taking up your time
if some one can help me that will be gr8
Code:
class Card:
suitList = ["Hearts", "Diamonds", "Clubs", "Spades"]
rankList = ["Invalid", "Ace", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "Jack", "Queen", "King"]
def __init__ (self, suit=0, rank=1):
if suit >= 0 and suit <= 3:
self.suit = suit
else:
self.suit = 0
if rank >= 1 and rank <= 13:
self.rank = rank
else:
self.rank = 1
def __str__(self):
return self.rankList[self.rank] + " of " + self.suitList[self.suit]
def __cmp__(self, other):
if self.rank > other.rank:
return 1
if self.rank < other.rank:
return -1
if self.suit > other.suit:
return 1
if self.suit < other.suit:
return -1
return 0
class Deck:
def __init__(self):
self.cards = []
for suit in range(4):
for rank in range(1,14):
self.cards.append(Card(suit, rank))
def __str__(self):
s = ""
for i in range(len(self.cards)):
s = s + (" " * i) + str(self.cards[i]) + "\n"
return s
def printDeck(self):
for card in self.cards:
print card
def main():
deck1 = Deck()
print "Original deck:"
print deck1
main()
Comment