When you run the code you should take a card from a set deck and from that I want it to display a write or wrong answer depending on if you type red or black by reading it, but no matter what I do it won't run the if statement.
import random
class Card(object):
def __init__(self, suit, num, color):
self.suit = suit
self.num = num
self.color = color
def show(self):
input("Red or Black ")
print("{} of {} ".format(self.num,self.suit))
if self.suit == "Hearts" or self.suit == "Diamonds":`enter code here`
self.color = "Red"
print("The color is {}".format(self.color) )
elif self.suit == "Spades" or self.suit == "Clubs":`enter code here`
self.color = "Black"
print("The color is " + self.color )
class Deck(object):
def __init__(self):
self.cards = []
self.build()
def build(self):
for i in ["Spades", "Hearts", "Diamonds", "Clubs"]:
for a in ["Red", "Black"]:
for j in range(0, 14):
self.cards.append(Card(j,i, a))
def shuffle(self):
for i in range(len(self.cards)-1, 0, -1):
r = random.randint(0, i)
self.cards[i], self.cards[r] = self.cards[r], self.cards[i]
def show(self):
for c in self.cards:
c.show()
def draw(self):
return self.cards.pop()
#def color(self):
class Player():
def __init__(self):
self.hand = []
def pick(self, deck):
self.hand.append(deck.draw())
return self
def showHand(self):
while True:
# x = input("Red or Black?: ").lower()
for card in self.hand:
card.show()
#if x == 'red':
deck = Deck()
deck.shuffle()
player = Player()
player.pick(deck)
player.showHand()
Aucun commentaire:
Enregistrer un commentaire