mardi 16 juin 2015

I'm learning Python, is there any bugs with my "draw two random cards"?

Are there any bugs with my code? The while statement is there to make sure you don't draw two of the same cards. Also, should I end the while statement with break or continue? Thanks in advance!

import random
card_values = ["the Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eigth", "Nine", "Ten", "Jack", "Quenn", "King"]
card_classes = [" of Hearts", " of Clubs", " of Diamonds", " of Spades"]
first_draw = random.choice(card_values) + random.choice(card_classes)
second_draw = random.choice(card_values) + random.choice(card_classes)
while first_draw == second_draw:
    first_draw = random.choice(card_values) + random.choice(card_classes)
    second_draw = random.choice(card_values) + random.choice(card_classes)
    break
print ("You drew " + first_draw + " and " + second_draw + "!")




Aucun commentaire:

Enregistrer un commentaire