Error to be resolved

Arun Nair nairarunv at gmail.com
Thu Oct 26 07:47:55 EDT 2006


These is the latest with the changes made:
=============================================================================================
from random import *
from string import *
class Card:

    def __init__(self, suit, rank):
        self.suit = suit
        self.rank = rank
        self.suit = ["None","Clubs","Diamonds","Hearts","Spades"]
        self.rank = ["zero", "Ace", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "Jack", "Queen", "King"]
        self.BJ = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]

    def getRank(self):
        return self.rank

    def getSuit(self):
        return self.suit

    def BJValue(self):
        return self.BJ

    def __str__(self):
        '''return " %s of %s(%s)" % (self.rank[self.rank],
self.suit[self.suit], self.BJ[self.rank])'''
        return self.rank + " of " + self.suit

def main():
    n = input("How many cards do you want to draw from the deck?")
    for i in range(n):
        a = randrange(1,13)
        b = randrange(1,4)
        c = Card(a,b)
        print c

main()
===============================================================================================
Still get an error:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>> Traceback (most recent call last):
  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "D:\Charles Sturt University\ITC106
200670\Assignment2\A2_3.1.py", line 33, in ?
    main()
  File "D:\Charles Sturt University\ITC106
200670\Assignment2\A2_3.1.py", line 31, in main
    print c
  File "D:\Charles Sturt University\ITC106
200670\Assignment2\A2_3.1.py", line 23, in __str__
    return self.rank + " of " + self.suit
TypeError: can only concatenate list (not "str") to list
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>




More information about the Python-list mailing list