# Deck of 52 cards list

Hi
Please help. I am stuck with deck card exercise around defining value for cards such as Ace, Queen, King, etc. The code I’ve written works to some degree.

import random

money = 100
#Write your game of chance functions here
def coin_flip(guess, bet):
num = random.randint(1,2)
if (num == 1) and (guess == “Heads”):
return money + bet
elif num == 2 and guess == “Tails”:
return money + bet
else:
return money - bet

def Cho_Hang(guess, bet):
num1 = random.randint(1,6)
num2 = random.randint(1,6)
num3 = num1 + num2
if (num3 % 2 == 0) and (guess == “Even”):
return money + bet, “Your bet is Even and is correct”
elif (num3 % 2 != 0) and (guess == “Odd”):
return money + bet, “Your bet is Odd and is correct”
else:
return money - bet, "Your bet ", guess, “is wrong”

#Card game
def card_deck(bet1, bet2):
deck = (“Ace”, 2, 3, 4, 5, 6, 7, 8, 9, 10, “Jack”, “Queen”, “King”,“Ace”, 2, 3, 4, 5, 6, 7, 8, 9, 10, “Jack”, “Queen”, “King”,“Ace”, 2, 3, 4, 5, 6, 7, 8, 9, 10, “Jack”, “Queen”, “King”,“Ace”, 2, 3, 4, 5, 6, 7, 8, 9, 10, “Jack”, “Queen”, “King”)
player1 = random.choice(deck)
player2 = random.choice(deck)
if player2 == player1:
return player2
else:
player2 = random.choice(deck)

if player1 > player2:
return money + bet1, “Player1 has chosen a card with highest number”, “Player1”, player1, “Player2”, player2
elif player1 < player2:
return money + bet2, “Player2 has chosen a card with highest number”, “Player2”, player2, “Player1”, player1
else:
return “It’s a tie”

#Call your game of chance functions here
print(Cho_Hang(“Odd”,3))
print(card_deck(4, 4))

Have you considered using dictionaries? Dictionaries have key value pairs

Sometimes young math students raise their hand in a classroom to get the attention of a teacher. Then, they proceed to describe their problem to the teacher, followed immediately by solving it themselves. The teacher didn’t have to say a single word.

Why did a difficult problem become easy, what did the student do?

They defined the problem.

So start with that, regardless of whether somebody else is helping you or you’re helping yourself.

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.