Mar-26-2017, 01:54 AM
(This post was last modified: Mar-26-2017, 01:57 AM by Liquid_Ocelot.)
Hey guys so I need to write a program that prints random cards from a list and prints it in a hand of 5 cards
card 1
card 2
card 3
card 4
card 5
I have figured out how to use the random.choice keyword but I am having a little bit of trouble with printing each card on a new line as my output just prints one random card 5 times instead of 5 random cards.....
output
For instance: Write a function that returns a card (e.g. "2 of Hearts", "Jack of Diamonds")
each time you call it. e.g. to deal a five card hand:
card 1
card 2
card 3
card 4
card 5
I have figured out how to use the random.choice keyword but I am having a little bit of trouble with printing each card on a new line as my output just prints one random card 5 times instead of 5 random cards.....
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import random suites = [ 'Hearts' , 'Diamonds' , 'Spades' , 'Clubs' ] cardFaces = [ 'Ace' , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 'Jack' , 'Queen' , 'King' ] pickACard = random.choice (suites) pickAFace = random.choice (cardFaces) hand = [] for i in range ( 5 ): # do the body five times card = pickACard , pickAFace hand.append(card) for card in hand: print (random.choice(hand)) |
1 2 3 4 5 6 7 |
( 'Diamonds' , 'King' ) ( 'Diamonds' , 'King' ) ( 'Diamonds' , 'King' ) ( 'Diamonds' , 'King' ) ( 'Diamonds' , 'King' ) Process finished with exit code 0 |
For instance: Write a function that returns a card (e.g. "2 of Hearts", "Jack of Diamonds")
each time you call it. e.g. to deal a five card hand: