import random class card: def __init__( self, num, suit ): self.suit=suit self.value=num def show( self ): print( self.value+self.suit ) class deck: def __init__( self ): self.cards = [] def add( self, num, suit): self.cards.append( card( num, suit ) ) def addCard( self, thiscard): self.cards.append( thiscard ) def showcards(self): for card in self.cards: card.show( ) def shuffle( self ): random.shuffle( self.cards ) def deal( self ): return self.cards.pop() class regDeck( deck ): def __init__( self ): self.cards = [] Suits=[" of Club", " of Diamonds", " of Spades", " of Hearts"] Values=["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"] for Suit in Suits: for Value in Values: self.cards.append( card( Value,Suit ) ) class unoDeck( deck ): def __init__( self ): self.cards = [] Suits=[" Red", " Green", " Yellow", " Blue"] Values=["1", "2", "3", "4", "5", "6", "7", "8", "9", "Draw 2", "Reverse", "Skip"] Wilds=["W"] Draw4=["D4"] for Suit in Suits: self.cards.append( card( "0", Suit) ) for Value in Values: self.cards.append( card( Value,Suit ) ) for i in range( 4 ): self.cards.append( card ( "W", "W" ) ) self.cards.append( card ( "W", "D4" ) ) myDeck=regDeck() myDeck.shuffle() myHand=deck() yourHand=deck() myHand.addCard( myDeck.deal() ) yourHand.addCard( myDeck.deal() ) myHand.addCard( myDeck.deal() ) yourHand.addCard( myDeck.deal() ) myHand.addCard( myDeck.deal() ) yourHand.addCard( myDeck.deal() ) myHand.addCard( myDeck.deal() ) yourHand.addCard( myDeck.deal() ) myHand.addCard( myDeck.deal() ) yourHand.addCard( myDeck.deal() ) print( "Ivo's Hand:" ) myHand.showcards() print( "Courtney's Hand:" ) yourHand.showcards() print('\u2663') print('\u2663')
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question