lundi 28 août 2017

How do you print values in lists with their index number in Python 2.7?

I am trying to make a Blackjack game in python. I ran into a problem because I am trying to use the random module with my game. I used the random module to get a number that coordinates with the index number in my list. The list I made consisted of card face values. I don't know how to print these values using the random index number, though. Here is my code:

# this is a blackjack game made in python
import random
import time

# make a list full of the card values
cards = (["A", "K", "Q", "J", 2, 3, 4, 5, 6, 7, 8, 9, 10])

indexNum1 = random.randint(0,12)
indexNum2 = random.randint(0,12)
indexNum3 = random.randint(0,12)
indexNum4 = random.randint(0,12)
indexNum5 = random.randint(0,12)

for card in cards:
    print card(indexNum1)
    print card(indexNum2)
    print card(indexNum3)
    print card(indexNum4)
    print card(indexNum5)

I hope someone can help me solve this problem. Thanks!




Aucun commentaire:

Enregistrer un commentaire