Aug-29-2022, 05:34 PM
(This post was last modified: Aug-29-2022, 06:30 PM by deanhystad.)
I don't think you can use random.randint() to draw a card, at least not if you want it to mimic drawing a card from a physical deck. What you've written is more like rolling a die. The difference is that when you draw cards from a deck you remove the cards. Those particular cards cannot be drawn again, and drawing a card changes the probability of what card is drawn next. When rolling a die the next roll is not affected in any way by the previous roll
To draw cards from a deck you should create a deck of cards, shuffle the deck, take cards off the top of the deck.
To draw cards from a deck you should create a deck of cards, shuffle the deck, take cards off the top of the deck.
import random # Create deck of cards that contains 8 infantry, 8 tanks, 4 planes deck = ["infantry"] * 8 + ["tank"] * 8 + ["plane"] * 4 random.shuffle(deck) print(deck)
Output:['tank', 'plane', 'tank', 'infantry', 'tank', 'tank', 'infantry', 'infantry', 'tank', 'infantry', 'plane', 'tank', 'infantry', 'infantry', 'infantry', 'plane', 'plane', 'tank', 'infantry', 'tank']
To draw a card from the deck just pop() off the first card. Now the deck contains 1 less card.