#🔒 game of card

56 messages · Page 1 of 1 (latest)

scenic locust
#

hello, i nedd some help for one of my project.
i need to create a game of card it's call "jeu de la bataille" in french but i don't know how to define/ create my pack of cards
it's juste the problem on the lign 2

import random
jeu
random.shuffle(jeu) #mélange jeu

milieu = len(jeu)//2
joueur1=jeu[:milieu]
joueur2=jeu[milieu:]

while joueur1 and joueur2:
cartej1=joueur1.pop(0) #j1 joue sa premiere carte
cartej2=joueur2.pop(0)
if cartej1>cartej2: #j1 remporte la manche
joueur1.extend([cartej1, cartej2])
print("joueur 1 gagne!")
elif cartej1<cartej2:
joueur2.extend([cartej1, cartej2])
print("joueur 2 gagne!")
#pour simplifier le programme: pas d'égalité (les cartes sont perdues)

Thank you for your help and excuse my english xD

edgy cometBOT
#

@scenic locust

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

twilit bison
#

What are the "cards" supposed to be? Strings? Objects with a suit/value?

scenic locust
scenic locust
twilit bison
#

So, do you need to replicate all the normal aspects of cards, like number and face cards, and suits?

scenic locust
scenic locust
scenic locust
twilit bison
#

So each card is basically just a number from 1-13?

#

And do you need 4 of each number?

scenic locust
scenic locust
twilit bison
#

Well, you can use a list comprehensions to create a list:

#

!e

cards = [card for card in range(1, 14)]
print(cards)
edgy cometBOT
twilit bison
#

This could also be just list(range(1, 14)), but a comprehension might make quadrupling each card easier

scenic locust
#

but I must have 4 times these values ​​for each symbol

#

my list should go 1 to 53 ?

#

because we have 52 card in the game

twilit bison
#

You could just generate 4 such lists and then combine them. You're shuffling them anyway, so the order they get created in doesn't matter.

scenic locust
#

how do you combine them?

twilit bison
#

You can use extend to add lists to other lists.

#

(Or the alias +=)

scenic locust
#

like listtotal=list1+list2+list3+list4 ?

#

i write this one my code ?

twilit bison
#

You can do that too. The main issue with that is + creates copies of the lists which wastes a bit of time. That shouldn't be a problem with your small lists though.

scenic locust
#

i use this :import random
jeu=list(range(0, 53))
random.shuffle(jeu) #mélange jeu

#

is it okay ? i think it's work!!

#

i just make all in one list

#

oh no i understand there is an error

twilit bison
#

That will create cards with values of 15-52

#

Which I don't think you want

scenic locust
#

import random
coeur=list(range(1, 14))
pique=list(range(1, 14))
carreau=list(range(1, 14))
trefle=list(range(1, 14))

jeu=list(coeur+pique+carreau+trefle)

random.shuffle(jeu) #mélange jeu

edgy cometBOT
#

Hey @scenic locust!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
scenic locust
#

i made this instead

#

with "coeur" is the list of earth symbol ...

#

and jeu is all the cards i think it's good ?

twilit bison
#

Yes, that looks better. The list call in jeu-list( is neccessary though. + is already returning a list.

scenic locust
#

jeu=(coeur+pique+carreau+trefle) just this is enough?

#

Thank you so much now it's work but my game never end xD

twilit bison
#

Or just jeu = coeur + pique + carreau + trefle

scenic locust
#

yeah you're wright its more simple

twilit bison
#

I prefer spaces around operators, and the () weren't necessary since the part they were wrapping were the only things on the right of the =.

scenic locust
#

yes sure, thank you so much

#

and sorry for my english

twilit bison
#

Np

scenic locust
#

just a last question if you can answer me, my code never end do you how to fix that?

#

import random
coeur=list(range(1, 14))
pique=list(range(1, 14))
carreau=list(range(1, 14))
trefle=list(range(1, 14))

jeu=coeur+pique+carreau+trefle

random.shuffle(jeu) #mélange jeu

milieu = len(jeu)//2
joueur1=jeu[:milieu]
joueur2=jeu[milieu:]

while joueur1 and joueur2:
cartej1=joueur1.pop(0) #j1 joue sa premiere carte
cartej2=joueur2.pop(0)
if cartej1>cartej2: #j1 remporte la manche
joueur1.extend([cartej1, cartej2])
print("joueur 1 gagne!")
elif cartej1<cartej2:
joueur2.extend([cartej1, cartej2])
print("joueur 2 gagne!")

edgy cometBOT
#

Hey @scenic locust!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
scenic locust
#

it's the whole code

verbal summit
#

When do you want it to end?

#

The while loop will end when joueur1 and joueur2 is no longer True

#

meaning: either joueur1 or joueur2 is False(y)

edgy cometBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.