while making a card game how can i make it so you cant draw the same card twice
Im trying to figure out how to get the program to recognize what card was drawn and remove it from the deck so it cant be drawn again. I know I could have don't a list of 52 where I have each item be a card name and pull it from that list and put it in a new list but with the way I did this that doesn't seem possible.
so how can I make it so it only draws a card one time?
import random
import time
played = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0]
def loop():
keepLooping = True
while(keepLooping):
global played
print ('The player with the lower card goes first')
print(' ')
# player One draw
draw = input("Player one would you like to draw?(y,n): ")
if draw == 'y':
CardNumber = random.randint(2,14)
Num2 = random.randint(2,4)
Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace"
cardnum1 = Royal.get(CardNumber, CardNumber)
suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
cardnum2 = suits[Num2]
DrawOne = [cardnum1, cardnum2]
print(DrawOne)
print(' ')
if draw == 'n':
print ('ok')
# player two draw
draw = input("Player Two would you like to draw?(y,n): ")
if draw == 'y':
CardNumber2 = random.randint(2,13)
Num3 = random.randint(2,4)
Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace"
cardnum3 = Royal.get(CardNumber2, CardNumber2)
suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
cardnum4 = suits[Num3]
DrawTwo = (cardnum3, cardnum4)
print(DrawTwo)
if draw == 'n':
print ('Then you lose')
# Win/lose/tie
if CardNumber == CardNumber2:
time.sleep(1)
print(' ')
print("it was a tie, lets re-draw")
print(' ')
keepLooping = True
else:
if CardNumber < CardNumber2:
keepLooping = False
time.sleep(.5)
print(' ')
print (DrawOne, 'Is the lower card, player 1 youre going first')
if CardNumber > CardNumber2:
keepLooping = False
time.sleep(.5)
print(' ')
print (DrawTwo, 'Is the lower card, player 2 youre going first')
loop()
python-3.x
add a comment |
Im trying to figure out how to get the program to recognize what card was drawn and remove it from the deck so it cant be drawn again. I know I could have don't a list of 52 where I have each item be a card name and pull it from that list and put it in a new list but with the way I did this that doesn't seem possible.
so how can I make it so it only draws a card one time?
import random
import time
played = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0]
def loop():
keepLooping = True
while(keepLooping):
global played
print ('The player with the lower card goes first')
print(' ')
# player One draw
draw = input("Player one would you like to draw?(y,n): ")
if draw == 'y':
CardNumber = random.randint(2,14)
Num2 = random.randint(2,4)
Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace"
cardnum1 = Royal.get(CardNumber, CardNumber)
suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
cardnum2 = suits[Num2]
DrawOne = [cardnum1, cardnum2]
print(DrawOne)
print(' ')
if draw == 'n':
print ('ok')
# player two draw
draw = input("Player Two would you like to draw?(y,n): ")
if draw == 'y':
CardNumber2 = random.randint(2,13)
Num3 = random.randint(2,4)
Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace"
cardnum3 = Royal.get(CardNumber2, CardNumber2)
suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
cardnum4 = suits[Num3]
DrawTwo = (cardnum3, cardnum4)
print(DrawTwo)
if draw == 'n':
print ('Then you lose')
# Win/lose/tie
if CardNumber == CardNumber2:
time.sleep(1)
print(' ')
print("it was a tie, lets re-draw")
print(' ')
keepLooping = True
else:
if CardNumber < CardNumber2:
keepLooping = False
time.sleep(.5)
print(' ')
print (DrawOne, 'Is the lower card, player 1 youre going first')
if CardNumber > CardNumber2:
keepLooping = False
time.sleep(.5)
print(' ')
print (DrawTwo, 'Is the lower card, player 2 youre going first')
loop()
python-3.x
Where is your question? What is the problem?
– BlueSheepToken
Nov 13 '18 at 22:54
title, I don't know how to make it so it only draw a card one time.
– J WALKAZ
Nov 13 '18 at 23:10
add a comment |
Im trying to figure out how to get the program to recognize what card was drawn and remove it from the deck so it cant be drawn again. I know I could have don't a list of 52 where I have each item be a card name and pull it from that list and put it in a new list but with the way I did this that doesn't seem possible.
so how can I make it so it only draws a card one time?
import random
import time
played = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0]
def loop():
keepLooping = True
while(keepLooping):
global played
print ('The player with the lower card goes first')
print(' ')
# player One draw
draw = input("Player one would you like to draw?(y,n): ")
if draw == 'y':
CardNumber = random.randint(2,14)
Num2 = random.randint(2,4)
Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace"
cardnum1 = Royal.get(CardNumber, CardNumber)
suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
cardnum2 = suits[Num2]
DrawOne = [cardnum1, cardnum2]
print(DrawOne)
print(' ')
if draw == 'n':
print ('ok')
# player two draw
draw = input("Player Two would you like to draw?(y,n): ")
if draw == 'y':
CardNumber2 = random.randint(2,13)
Num3 = random.randint(2,4)
Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace"
cardnum3 = Royal.get(CardNumber2, CardNumber2)
suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
cardnum4 = suits[Num3]
DrawTwo = (cardnum3, cardnum4)
print(DrawTwo)
if draw == 'n':
print ('Then you lose')
# Win/lose/tie
if CardNumber == CardNumber2:
time.sleep(1)
print(' ')
print("it was a tie, lets re-draw")
print(' ')
keepLooping = True
else:
if CardNumber < CardNumber2:
keepLooping = False
time.sleep(.5)
print(' ')
print (DrawOne, 'Is the lower card, player 1 youre going first')
if CardNumber > CardNumber2:
keepLooping = False
time.sleep(.5)
print(' ')
print (DrawTwo, 'Is the lower card, player 2 youre going first')
loop()
python-3.x
Im trying to figure out how to get the program to recognize what card was drawn and remove it from the deck so it cant be drawn again. I know I could have don't a list of 52 where I have each item be a card name and pull it from that list and put it in a new list but with the way I did this that doesn't seem possible.
so how can I make it so it only draws a card one time?
import random
import time
played = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0]
def loop():
keepLooping = True
while(keepLooping):
global played
print ('The player with the lower card goes first')
print(' ')
# player One draw
draw = input("Player one would you like to draw?(y,n): ")
if draw == 'y':
CardNumber = random.randint(2,14)
Num2 = random.randint(2,4)
Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace"
cardnum1 = Royal.get(CardNumber, CardNumber)
suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
cardnum2 = suits[Num2]
DrawOne = [cardnum1, cardnum2]
print(DrawOne)
print(' ')
if draw == 'n':
print ('ok')
# player two draw
draw = input("Player Two would you like to draw?(y,n): ")
if draw == 'y':
CardNumber2 = random.randint(2,13)
Num3 = random.randint(2,4)
Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace"
cardnum3 = Royal.get(CardNumber2, CardNumber2)
suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
cardnum4 = suits[Num3]
DrawTwo = (cardnum3, cardnum4)
print(DrawTwo)
if draw == 'n':
print ('Then you lose')
# Win/lose/tie
if CardNumber == CardNumber2:
time.sleep(1)
print(' ')
print("it was a tie, lets re-draw")
print(' ')
keepLooping = True
else:
if CardNumber < CardNumber2:
keepLooping = False
time.sleep(.5)
print(' ')
print (DrawOne, 'Is the lower card, player 1 youre going first')
if CardNumber > CardNumber2:
keepLooping = False
time.sleep(.5)
print(' ')
print (DrawTwo, 'Is the lower card, player 2 youre going first')
loop()
python-3.x
python-3.x
edited Nov 13 '18 at 23:11
J WALKAZ
asked Nov 13 '18 at 22:46
J WALKAZJ WALKAZ
113
113
Where is your question? What is the problem?
– BlueSheepToken
Nov 13 '18 at 22:54
title, I don't know how to make it so it only draw a card one time.
– J WALKAZ
Nov 13 '18 at 23:10
add a comment |
Where is your question? What is the problem?
– BlueSheepToken
Nov 13 '18 at 22:54
title, I don't know how to make it so it only draw a card one time.
– J WALKAZ
Nov 13 '18 at 23:10
Where is your question? What is the problem?
– BlueSheepToken
Nov 13 '18 at 22:54
Where is your question? What is the problem?
– BlueSheepToken
Nov 13 '18 at 22:54
title, I don't know how to make it so it only draw a card one time.
– J WALKAZ
Nov 13 '18 at 23:10
title, I don't know how to make it so it only draw a card one time.
– J WALKAZ
Nov 13 '18 at 23:10
add a comment |
1 Answer
1
active
oldest
votes
Easy way conceptually (and not using numpy):
>>> cards = list(range(52))
>>> random.shuffle(cards)
>>> cards
[7, 28, 1, 49, 27, 36, 26, 16, 32, 23, 45, 19, 31, 13, 44, 5, 37, 3, 39, 29, 42, 11, 46, 6, 2, 0, 15, 14, 48, 38, 9, 51, 10, 20, 43, 25, 18, 12, 8, 21, 47, 4, 33, 24, 41, 50, 35, 17, 40, 22, 34, 30]
Now everytime you draw, you can pop one from the list.
>>> card = cards.pop()
>>> card
30
Then to get the suit and the number, you can do this:
suit = card % 4 # e.g. 0 is hearts, etc. (arbitrary)
number = card % 13 + 1 # so that 1 is 1, and 11 is Jack
In case modulo (%
) is not familiar, please have a look here: How does % work in Python?
to make sure I understand are you saying replace this?CardNumber = random.randint(2,14) Num2 = random.randint(2,4) Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace" cardnum1 = Royal.get(CardNumber, CardNumber) suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
– J WALKAZ
Nov 13 '18 at 23:31
I'm sure you can figure it out using this. Final clue:suit
will be a number, so you still need to convert it indeed using your "suits" dictionary, these parts didn't change.
– PascalVKooten
Nov 13 '18 at 23:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290660%2fwhile-making-a-card-game-how-can-i-make-it-so-you-cant-draw-the-same-card-twice%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Easy way conceptually (and not using numpy):
>>> cards = list(range(52))
>>> random.shuffle(cards)
>>> cards
[7, 28, 1, 49, 27, 36, 26, 16, 32, 23, 45, 19, 31, 13, 44, 5, 37, 3, 39, 29, 42, 11, 46, 6, 2, 0, 15, 14, 48, 38, 9, 51, 10, 20, 43, 25, 18, 12, 8, 21, 47, 4, 33, 24, 41, 50, 35, 17, 40, 22, 34, 30]
Now everytime you draw, you can pop one from the list.
>>> card = cards.pop()
>>> card
30
Then to get the suit and the number, you can do this:
suit = card % 4 # e.g. 0 is hearts, etc. (arbitrary)
number = card % 13 + 1 # so that 1 is 1, and 11 is Jack
In case modulo (%
) is not familiar, please have a look here: How does % work in Python?
to make sure I understand are you saying replace this?CardNumber = random.randint(2,14) Num2 = random.randint(2,4) Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace" cardnum1 = Royal.get(CardNumber, CardNumber) suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
– J WALKAZ
Nov 13 '18 at 23:31
I'm sure you can figure it out using this. Final clue:suit
will be a number, so you still need to convert it indeed using your "suits" dictionary, these parts didn't change.
– PascalVKooten
Nov 13 '18 at 23:33
add a comment |
Easy way conceptually (and not using numpy):
>>> cards = list(range(52))
>>> random.shuffle(cards)
>>> cards
[7, 28, 1, 49, 27, 36, 26, 16, 32, 23, 45, 19, 31, 13, 44, 5, 37, 3, 39, 29, 42, 11, 46, 6, 2, 0, 15, 14, 48, 38, 9, 51, 10, 20, 43, 25, 18, 12, 8, 21, 47, 4, 33, 24, 41, 50, 35, 17, 40, 22, 34, 30]
Now everytime you draw, you can pop one from the list.
>>> card = cards.pop()
>>> card
30
Then to get the suit and the number, you can do this:
suit = card % 4 # e.g. 0 is hearts, etc. (arbitrary)
number = card % 13 + 1 # so that 1 is 1, and 11 is Jack
In case modulo (%
) is not familiar, please have a look here: How does % work in Python?
to make sure I understand are you saying replace this?CardNumber = random.randint(2,14) Num2 = random.randint(2,4) Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace" cardnum1 = Royal.get(CardNumber, CardNumber) suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
– J WALKAZ
Nov 13 '18 at 23:31
I'm sure you can figure it out using this. Final clue:suit
will be a number, so you still need to convert it indeed using your "suits" dictionary, these parts didn't change.
– PascalVKooten
Nov 13 '18 at 23:33
add a comment |
Easy way conceptually (and not using numpy):
>>> cards = list(range(52))
>>> random.shuffle(cards)
>>> cards
[7, 28, 1, 49, 27, 36, 26, 16, 32, 23, 45, 19, 31, 13, 44, 5, 37, 3, 39, 29, 42, 11, 46, 6, 2, 0, 15, 14, 48, 38, 9, 51, 10, 20, 43, 25, 18, 12, 8, 21, 47, 4, 33, 24, 41, 50, 35, 17, 40, 22, 34, 30]
Now everytime you draw, you can pop one from the list.
>>> card = cards.pop()
>>> card
30
Then to get the suit and the number, you can do this:
suit = card % 4 # e.g. 0 is hearts, etc. (arbitrary)
number = card % 13 + 1 # so that 1 is 1, and 11 is Jack
In case modulo (%
) is not familiar, please have a look here: How does % work in Python?
Easy way conceptually (and not using numpy):
>>> cards = list(range(52))
>>> random.shuffle(cards)
>>> cards
[7, 28, 1, 49, 27, 36, 26, 16, 32, 23, 45, 19, 31, 13, 44, 5, 37, 3, 39, 29, 42, 11, 46, 6, 2, 0, 15, 14, 48, 38, 9, 51, 10, 20, 43, 25, 18, 12, 8, 21, 47, 4, 33, 24, 41, 50, 35, 17, 40, 22, 34, 30]
Now everytime you draw, you can pop one from the list.
>>> card = cards.pop()
>>> card
30
Then to get the suit and the number, you can do this:
suit = card % 4 # e.g. 0 is hearts, etc. (arbitrary)
number = card % 13 + 1 # so that 1 is 1, and 11 is Jack
In case modulo (%
) is not familiar, please have a look here: How does % work in Python?
edited Nov 13 '18 at 23:28
answered Nov 13 '18 at 23:21
PascalVKootenPascalVKooten
9,977958110
9,977958110
to make sure I understand are you saying replace this?CardNumber = random.randint(2,14) Num2 = random.randint(2,4) Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace" cardnum1 = Royal.get(CardNumber, CardNumber) suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
– J WALKAZ
Nov 13 '18 at 23:31
I'm sure you can figure it out using this. Final clue:suit
will be a number, so you still need to convert it indeed using your "suits" dictionary, these parts didn't change.
– PascalVKooten
Nov 13 '18 at 23:33
add a comment |
to make sure I understand are you saying replace this?CardNumber = random.randint(2,14) Num2 = random.randint(2,4) Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace" cardnum1 = Royal.get(CardNumber, CardNumber) suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
– J WALKAZ
Nov 13 '18 at 23:31
I'm sure you can figure it out using this. Final clue:suit
will be a number, so you still need to convert it indeed using your "suits" dictionary, these parts didn't change.
– PascalVKooten
Nov 13 '18 at 23:33
to make sure I understand are you saying replace this?
CardNumber = random.randint(2,14) Num2 = random.randint(2,4) Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace" cardnum1 = Royal.get(CardNumber, CardNumber) suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
– J WALKAZ
Nov 13 '18 at 23:31
to make sure I understand are you saying replace this?
CardNumber = random.randint(2,14) Num2 = random.randint(2,4) Royal = 11: "Jack",12: "Queen",13: "King",14: "Ace" cardnum1 = Royal.get(CardNumber, CardNumber) suits = 1: "Spades", 2: "Hearts", 3: "Diamonds", 4: "Clubs"
– J WALKAZ
Nov 13 '18 at 23:31
I'm sure you can figure it out using this. Final clue:
suit
will be a number, so you still need to convert it indeed using your "suits" dictionary, these parts didn't change.– PascalVKooten
Nov 13 '18 at 23:33
I'm sure you can figure it out using this. Final clue:
suit
will be a number, so you still need to convert it indeed using your "suits" dictionary, these parts didn't change.– PascalVKooten
Nov 13 '18 at 23:33
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290660%2fwhile-making-a-card-game-how-can-i-make-it-so-you-cant-draw-the-same-card-twice%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Where is your question? What is the problem?
– BlueSheepToken
Nov 13 '18 at 22:54
title, I don't know how to make it so it only draw a card one time.
– J WALKAZ
Nov 13 '18 at 23:10