Ask coding questions

← Back to all posts
[HELP PLEASE] A game needs some help, Python 3
peternielsen112

Basically, I'm wondering how to get the logic in the game (the above REPL) to check if the amount of cards in the player's hand is equal to the amount of any one suit in the hand.

Thank you REPL.it for helping.

Voters
peternielsen112
Comments
hotnewtop
RYANTADIPARTHI

You need to make an if statement to get it to check if the number of cards is correct.

peternielsen112

@RYANTADIPARTHI I know that, it doesn't seem to be working! That's the problem. Sorry for not explaining well

peternielsen112

wait a second if I make it a set number of cards... will it work? Any guesses?

peternielsen112

I'm going to try reworking it...

peternielsen112

i just don't see why its not working...

IndyRishi

I got an error saying Traceback (most recent call last):
File "main.py", line 18, in <module>
cards.deal(cardnum)
File "/home/runner/zjrwjnwe4b9/cards.py", line 34, in deal
carddrawn = random.choice(deck)
File "/usr/lib/python3.8/random.py", line 290, in choice
raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence

peternielsen112

@IndyRishi there were no cards left in the deck...

peternielsen112

so somehow you ended up drawing too many cards
I'll add a failsafe later to fix that but i need the logic to finish it

Coder100

ok ok, so if I remember correctly, suites have 13 cards, so that means, we have something like:

but maybe I am understanding this wrong as you can specify a deal that would render this statement to be never true...

peternielsen112

@Coder100 so basically, the player chooses how many cards to deal. Then I want an if loop like:
#pseudocode
if hearts-in-hand == cards-in-hand:
win

peternielsen112

so does that make sense?

Coder100
Coder100

then wouldn't you just implement it like that?

@peternielsen112

peternielsen112

@Coder100 it's basically what I did...

Coder100

ohhhhhhh ok ok so sorry @peternielsen112

peternielsen112

@Coder100 no actually I just realized I was beating around the bush and making random useless variables...

Coder100
peternielsen112

@Coder100 but it might work now... just a sec

peternielsen112

@Coder100 not about this problem but do you use Mr. Economical's repl mail? if so could you check it and I sent you something

Coder100

1 question, what is the variable num? is that the combination of all the cards?

peternielsen112

@Coder100 I don't see what youre looking at what line

Coder100

@peternielsen112 line 12, *cardnum

peternielsen112

@Coder100 that sets the hand at 0 until the player chooses how many cards to deal

Coder100

hi! you told me to help, so I'm looking on to it!

peternielsen112

@Coder100 thanks again

Coder100