lundi 15 juin 2015

Select a random card from list in python

so I need to make a "game" where the user is ask if he wants to select a card and if yes, then a random card will be returned. something like this:

>>>selectCard()
Would you like to draw a random card? (yes/no)
>>>yes
The card you got is: 8 of hearts
>>>selectCard()
Would you like to draw a random card? (yes/no)
>>>yes
The card you got is: Ace of diamonds

so far I have this but I am stuck and don't know how to finish it

def selectCards():
cardranks = ['Ace',1,2,3,4,5,6,7,8,9,'Jack','Queen','King','Ace',1,2,3,4,5,6,7,8,9,'Jack','Queen','King','Ace',1,2,3,4,5,6,7,8,9,'Jack','Queen','King','Ace',1,2,3,4,5,6,7,8,9,'Jack','Queen','King']
cardsuits = ['of Clubs','of Clubs','of Clubs','of Clubs','of Clubs','of Clubs','of Clubs','of Clubs','of Clubs','of Clubs','of Clubs','of Clubs','of Clubs','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Diamonds','of Hearts','of Hearts','of Hearts','of Hearts','of Hearts','of Hearts','of Hearts','of Hearts','of Hearts','of Hearts','of Hearts','of Hearts','of Hearts','of Spades','of Spades','of Spades','of Spades','of Spades','of Spades','of Spades','of Spades','of Spades','of Spades','of Spades','of Spades','of Spades']
shuffle(cardranks)
shuffle(cardsuits)
for a,b in zip(cardranks,cardsuits):
    responce = (input ('Would you like to draw a random card? (yes/no)'))
    if responce == yes:
        return (a,b)

when I run this piece of program it says that yes is not defined and so I don't know how to continue.

Thank you




Aucun commentaire:

Enregistrer un commentaire