doesnt seems to work can any help be provided

A

Arun Nair

import string

class Card:

# Not sure if I need to set these first???
# suitList = ()
# rankList = ()

def __init__(self,suit,rank):
self.suit = suit
self.rank = rank

def __repr__(self):
return str(self)

def __str__(self):
return "%s of %s" %
(self.rankList[self.rank],self.suitList[self.suit])

def __cmp__(self,other):
if self.suit > other.suit:
return 1
if self.suit < other.suit:
return -1
if self.rank > other.rank:
return 1
if self.rank < other.rank:
return -1
else:
return 0

def getCard(cards):
# Break each card into suit and rank
rankList , suitList = string.split(cards," ")
return Card(rankList,suitList)

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 main():
# Open the file with the cards in them
filename = raw_input('Enter the file name for the cards >>')
infile = open(filename,'r')

# Set the first card in the list
cards = getCard(infile.readline())

# Process the extra lines
for line in infile:
s = getCard(line)
infile.close()
a=Deck()
print a


main()
 
B

Bruno Desthuilliers

Arun said:
import string

You don't need it. Use "some string".split() instead
class Card:

class Card(object):
# Not sure if I need to set these first???
Not only do you need to define them, but it would probably be a good
idea to populate them. And BTW, () is a tuple, not a list (but tuples
are perfectly ok for this use case).
# suitList = ()
# rankList = ()


(snip whole code listing)

Do you really expect us to run your code, fix the bugs and send it back?
Or are we supposed to guess what's "not working" ?

Please take a few minutes to read this:
http://catb.org/esr/faqs/smart-questions.html

with particular attention to the following point:
http://catb.org/esr/faqs/smart-questions.html#beprecise

HTH
 
S

Steve Holden

Arun Nair wrote:
[stuff]

You will find people are willing to help, even sometimes with homework
questions, when questioners show some evidence that they are looking to
learn rather than simply to have their problems solved for them.

regards
Steve
 
G

Grant Edwards

import string

class Card:

Could you please keep this homework assignment in a single
thread in order to make it easier to ignore for those of us who
don't want to work on this particular homework problem for you?

If not, then you're likely to get get killfiled by many people
(all your postings will get ignored).
 
B

Ben Finney

Bruno Desthuilliers said:
Arun said:
[more homework assignments, not working]
Do you really expect us to run your code, fix the bugs and send it
back?

Yes, he apparently does. He's told us that it's homework, but that he
hasn't learned enough from his teacher.

Apparently that learning also didn't include the prohibitions against
colluding with others. Nevertheless, I'll bet they are still present.
Please take a few minutes to read this:
http://catb.org/esr/faqs/smart-questions.html

with particular attention to the following point:
http://catb.org/esr/faqs/smart-questions.html#beprecise

In this case, a better section is:

Grovelling is not a substitute for doing your homework
<URL:http://catb.org/esr/faqs/smart-questions.html#id273364>
 
F

Fredrik Lundh

Ben said:
Apparently that learning also didn't include the prohibitions against
colluding with others. Nevertheless, I'll bet they are still present.

http://www.csu.edu.au/acad_sec/manuals/gcontm.htm

Part G6

Collusion

A student colludes when he or she works without permission with
another person or persons to produce work which is then presented as
work completed independently by the student.

Collusion includes, but is not limited to:

- writing the whole or part of an assignment with another person;

- using the notes of another person to prepare an assignment;

- using for an assignment the resource materials of another person
that have been annotated or parts of the text highlighted or
underlined by that person;

- allowing another student, who has to submit an assignment on the
same topic, access to one's own assignment under conditions which
would give that other student an advantage in submitting his or her
assignment

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Error to be resolved 4
Python: Code is ignoring the if and else 11
Tkinter help, please... 3
Constructor problem 5
Python battle game help 2
totally lost newbie 3
Newbie help understanding... 2
Cards deck problem 13

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top