Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python problems with integer comparision

Tags:

python

I'm using a function in a card game, to check the value of each card, and see if it is higher than the last card played.

def Valid(card):
prev=pile[len(pile)-1]
cardValue=0
prevValue=0
if card[0]=="J":
    cardValue=11
elif card[0]=="Q":
    cardValue=12
elif card[0]=="K":
    cardValue=13
elif card[0]=="A":
    cardValue=14
else:
    cardValue=card[0]
prevValue=prev[0]
if cardValue>prevValue:
    return True
elif cardValue==prevValue:
    return True
else:
    return False

The problem is, whenever I get a facecard, it doesnt seem to work. It thinks 13>2 is True, for example

edit: sorry, I meant it thinks 13>2 is False

like image 991
yam Avatar asked Sep 08 '10 21:09

yam


1 Answers

I think what you meant is that it is saying that "2" > 13 which is true. You need to change

cardValue=card[0]

to

cardValue=int(card[0])
like image 150
Justin Peel Avatar answered Sep 30 '22 15:09

Justin Peel