mercredi 6 juin 2018

Selecting more than one random selection in a list

I want to have two separate random selections from the same list. Is there any way to do this that doesn't include making separate lists?

import random


cards = [2,3,4,5,6,7,8,9,10,'King','Queen','Jack']
cards = random.choice(cards)

suits = ['Clubs', 'Hearts', 'Spades', 'Diamonds']
suits = random.choice(suits)

first_card = ("your first card is the {} of {}") .format(cards,suits)
second_card = ("your second card is the {} of {}") .format(cards,suits)

print first_card
print second_card

Output

your first card is the 10 of Spades
your second card is the 10 of Spades

I want the output to be the same but the last card dealt is different from the first; two separate cards




Aucun commentaire:

Enregistrer un commentaire