Python Forum
card dealer school project
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
card dealer school project
#1
hi, i need help with a school project with python. the program i must do is following:
"do a code which creates a mixed deck of cards and then distributes five cards to as many players as the user wishes"
dont know how to start!
Thanks!
Reply
#2
Start here: http://openbookproject.net/thinkcs/pytho...tions.html
Reply
#3
okey but the problem is that i cant get it go give diffrent cards(random) to the players. it gives out the same 5 cards for the chooosen players. I want it to give 5 random cards to the players. "card dealer"

rank = ""
 
suit = ""
import random
r = random.randint(1,13)
s = random.randint(1,4)
 
 
 
if s == 1:
    suit = "spades"
elif s == 2:
    suit = "heart"
elif s == 3:
    suit = "diamond"
elif s == 4:
    suit = "clubs"
 
if r == 11:
    rank = "jack"
 
elif r == 12:
    rank = "queen"
 
elif r == 13:
    rank = "King"
 
elif r > 1 and r < 11:
    rank = r
i=int(input('how many players are gonna play poker?'))
def poker (i):
    if i>0:
        print('player', +i, 'gets the cards')
        print(suit, rank)
        print(suit, rank)
        print(suit, rank)
        print(suit, rank)
        print(suit, rank)
        i-=1
        r = random.randint(1,13)
        s = random.randint(1,4)
    print(poker(i))
 
 
 
 
print(poker(i))
Reply
#4
You're not changing suit or rank for one thing, so yeah, they are always going to be the same. And you are creating them at random, rather than as a deck, so you could end up giving five twos of clubs to the same player.

Create a list of all the cards in the deck (looping through all of the ranks, then looping through all of the cards). Use random.shuffle to mix up the list. Deal the cards from the deck using pop or slicing.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
(Jan-05-2019, 07:15 PM)ichabod801 Wrote: You're not changing suit or rank for one thing, so yeah, they are always going to be the same. And you are creating them at random, rather than as a deck, so you could end up giving five twos of clubs to the same player.

Create a list of all the cards in the deck (looping through all of the ranks, then looping through all of the cards). Use random.shuffle to mix up the list. Deal the cards from the deck using pop or slicing.

ive done this and it still does not work. didnt understand what u mean

import itertools, random

# make a deck of cards
deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club']))

# shuffle the cards
random.shuffle(deck)
i=int(input('how many are going to play?'))

def poker(i):

    print("player", i,'gets')
    for i in range(5):
        print(deck[i][0], "of", deck[i][1])
        i-=1
        print(poker(i))

print(poker(i))
Reply
#6
You are making a recursive call on line 16. You don't want that, just do it in a loop. Have an another for loop (containing the current one) that loops through the number of players. Note that you are using i as the number of players (line 8) and how many cards to deal each player (line 13). You need two separate variables for that. You should name them something more descriptive than i (like num_players and num_cards), so that your code is easier to understand.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  my python project for school vavervirus 2 601 Oct-12-2023, 03:28 AM
Last Post: buran
Shocked School project -- need help with it it says syntax error XPGKNIGHT 6 3,255 Aug-11-2022, 08:43 PM
Last Post: deanhystad
  School project janivar91 3 2,646 Jan-23-2021, 06:31 AM
Last Post: KonohaHokage
  Python School Project andreas30298 2 2,101 Nov-12-2020, 09:58 AM
Last Post: Axel_Erfurt
  I need help for a school project IndyNeerhoff 1 2,039 Sep-28-2019, 08:28 PM
Last Post: Gribouillis
  Turtle Graphics Card Values in a List Muzz 0 2,326 Apr-11-2019, 12:55 PM
Last Post: Muzz
  [Tkinter] Tkinter project school Kersow 2 2,444 Apr-08-2019, 08:45 PM
Last Post: Larz60+
  Playing Card Sorting ness828 4 62,543 Feb-05-2018, 09:01 PM
Last Post: sparkz_alot
  Small game (school project) Ganesh 7 5,586 Nov-08-2017, 09:04 PM
Last Post: Ganesh
  card 21 trick SummoningZ 21 15,694 Aug-24-2017, 12:42 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020