Texas hold-em project not working and randomly not responding and skipping code plz help
also could someone tell me how to show u guys the project plz thx
Welcome! Have you read the about page? It shows you how to format code so we can read it; that’s the best way to share the project (as long as it’s not overly long).
Hi @Andrew5057, a little off topic, but I’ve struggled to find it w/o the link that someone else has supplied.
Where can I find it from the either the main home page, or even just Python Help - Discussions on Python.org.
So I couldn’t find it until I logged out. It turned out I must have unpinned it some time ago.
It’s pinned again now.
I don’t know the problem and what specific part of the code isn’t working and the code is pretty long this was uploaded a while ago and I have a deadline of next wednesday
Usually you can use ctrl+A then ctrl+C to copy the whole code.
If the length of the code is beyond some limits, use git and you can manage, or upload to github to show your code.
You have some examples online that could give some inspiration or ask AI for some help!
If you are still interested to get help, we will also need the error(s) you are getting.
im on a school computer so I can’t use GitHub but here’s the code I guess keep in mind this code is on code.org python not regular python so some soulutions might not work
#setup
p1_ctotal = 10000
fold_chance = 0
fold_chance2 = 0
fold_chance3 = 0
card_suit1 = ('♠', '♥', '♦', '♣')
card_val1 = ('2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A')
fold_chance = 0
bid_pool = 0
total_M = 3000
is_p1_folded = False
is_npc1_folded = False
is_npc2_folded = False
import time
import random
import sys
response1 = input("play? Y/N? ")
keywords1 = ('Y' 'y' 'yes' 'yeah' 'Yes' 'Yeah')
#play or not
if any(word in response1 for word in keywords1):
print("game started! -10 chips")
else:
print("starting game anyway! -10 chips")
bid_pool = bid_pool + 10
time.sleep(5)
#dealing cards
card_suit_ran1 = random.choice(card_suit1)
card_suit_ran2 = random.choice(card_suit1)
card_val_ran1 = random.choice(card_val1)
card_val_ran2 = random.choice(card_val1)
card_suit_ran3 = random.choice(card_suit1)
card_suit_ran4 = random.choice(card_suit1)
card_val_ran3 = random.choice(card_val1)
card_val_ran4 = random.choice(card_val1)
card_suit_ran5 = random.choice(card_suit1)
card_suit_ran6 = random.choice(card_suit1)
card_val_ran5 = random.choice(card_val1)
card_val_ran6 = random.choice(card_val1)
card1 = card_suit_ran1 + card_val_ran1
card2 = card_suit_ran2 + card_val_ran2
print ("cards dealt", card1, card2)
npccard1 = card_suit_ran3 + card_val_ran3
npccard2 = card_suit_ran4 + card_val_ran4
npccard3 = card_suit_ran5 + card_val_ran5
npccard4 = card_suit_ran6 + card_val_ran6
print ("Jeff cards", npccard1, npccard2)
print ("jeff2 cards", npccard3, npccard4)
#1st_round_npcs
time.sleep(3)
if card_val_ran1 in npccard1 != card_val_ran2 in npccard2:
fold_chance = ran.randint(1,9)
if fold_chance > 6:
print("Jeff folded")
is_npc1_folded = True
else:
bid_1 = random.randint(1,9)
bid1 = bid_1 * 10
print("Jeff stands")
bid_pool = bid1 * 3 + bid_pool
print("bid pool is now", bid_pool)
p1_ctotal = p1_ctotal - bid_1
time.sleep(3)
if card_val_ran2 in npccard1 != card_val_ran3 in npccard2:
fold_chance2 = random.randint(1,9)
if fold_chance2 > 5:
print("Jeff2 folded")
is_npc2_folded = True
else:
bid_2 = random.randint(1,9)
bid2 = bid_2 * 10
print("Jeff2 stands")
bid_pool = bid2 * 3 + bid_pool
print("bid pool is now", bid_pool)
p1_ctotal = p1_ctotal - bid_2
if is_npc1_folded == True:
if is_npc2_folded == True:
SystemExit()
foldyn = input(f"you've lost {bid_pool / 3} and your cards are {card1} and {card2} fold Y/N? ")
if any(word in foldyn for word in keywords1):
print("p1 folded!")
is_p1_folded = True
else:
print("p1 stands")
p_bid = input("bid 10 20 30 40 50 60 70 80 or 90 ")
intp_bid = int(p_bid)
bid_pool = intp_bid * 3 + bid_pool
print("bid pool is now", bid_pool)
p1_ctotal = p1_ctotal - intp_bid
time.sleep(2)
#flop / 2nd betting round
card_suit_ran7 = random.choice(card_suit1)
card_val_ran7 = random.choice(card_val1)
card_suit_ran8 = random.choice(card_suit1)
card_val_ran8 = random.choice(card_val1)
card_suit_ran9 = random.choice(card_suit1)
card_val_ran9 = random.choice(card_val1)
flop_card1 = card_suit_ran7 + card_val_ran7
flop_card2 = card_suit_ran8 + card_val_ran3
flop_card3 = card_suit_ran9 + card_val_ran9
print(f"flop is {flop_card1} {flop_card2} and {flop_card3}")
time.sleep(2)
fold_chance3 = random.randint(1,9)
if is_npc1_folded == False:
if card_val_ran3 != card_val_ran7:
if card_val_ran3 != card_val_ran8:
if card_val_ran3 != card_val_ran9:
if card_val_ran4 != card_val_ran7:
if card_val_ran4 != card_val_ran8:
if card_val_ran4 != card_val_ran9:
if fold_chance3 > 6:
print("Jeff folded")
is_npc1_folded = True
elif fold_chance3 > 8:
print("Jeff folded")
is_npc1_folded = True
else:
print("Jeff stands")
bid_3 = random.randint(1,9)
bid3 = bid_3 * 10
p1_ctotal = p1_ctotal - bid3
bid_pool = bid3 * 3 + bid_pool
print("bid pool is now", bid_pool)
time.sleep(2)
fold_chance4 = random.randint(1,9)
if is_npc2_folded == False:
if card_val_ran5 != card_val_ran7:
if card_val_ran5 != card_val_ran8:
if card_val_ran5 != card_val_ran9:
if card_val_ran6 != card_val_ran7:
if card_val_ran6 != card_val_ran8:
if card_val_ran6 != card_val_ran9:
if fold_chance4 > 5:
print("Jeff2 folded")
is_npc2_folded = True
elif fold_chance4 > 9:
print("Jeff2 folded")
is_npc2_folded = True
else:
print("Jeff2 stands")
bid_4 = random.randint(1,9)
bid4 = bid_4 * 10
p1_ctotal = p1_ctotal - bid4
bid_pool = bid4 * 3 + bid_pool
print("bid pool is now", bid_pool)
if is_npc1_folded == True:
if is_npc2_folded == True:
print(f"You win! {bid_pool} chips! " )
sys.exit()
if is_p1_folded == False:
foldyn = input(f"you've lost {bid_pool / 3}, your cards are {card1} and {card2}, and the flop is {flop_card1}, {flop_card2}, and {flop_card3} fold Y/N? ")
if any(word in foldyn for word in keywords1):
print("p1 folded!")
is_p1_folded = True
else:
print("p1 stands")
p_bid = input("bid 10 20 30 40 50 60 70 80 or 90 ")
intp_bid = int(p_bid)
bid_pool = intp_bid * 3 + bid_pool
print("bid pool is now", bid_pool)
p1_ctotal = p1_ctotal - intp_bid
if is_p1_folded == True:
if is_npc1_folded == True:
print(f"jeff2 won! {bid_pool} chips! " )
sys.exit()
if is_p1_folded == True:
if is_npc2_folded == True:
print(f"jeff won! {bid_pool} chips! " )
sys.exit()
#turn / 3rd betting round
card_suit = random.choice(card_suit1)
card_val = random.choice(card_val1)
turn_card = card_suit + card_val
print(f"turn_card is {turn_card}")
if is_npc1_folded == False:
if card_val_ran3 != card_val:
if card_val_ran4 != card_val:
fold_chance = random.randint(1,9)
if fold_chance > 7:
print("Jeff folded")
is_npc1_folded = True
elif fold_chance > 8:
print("Jeff folded")
is_npc1_folded = True
else:
print("Jeff stands")
bid_5 = random.randint(1,9)
bid5 = bid_5 * 10
p1_ctotal = p1_ctotal - bid5
bid_pool = bid5 * 3 + bid_pool
print("bid pool is now", bid_pool)
time.sleep(2)
print('.')
if is_npc2_folded == False:
if card_val_ran5 != card_val:
if card_val_ran6 != card_val:
fold_chance = random.randint(1,9)
if fold_chance > 7:
print("Jeff2 folded")
is_npc1_folded = True
elif fold_chance > 8:
print("Jef2f folded")
is_npc2_folded = True
else:
print("Jeff stands")
bid_6= random.randint(1,9)
bi6 = bid_6 * 10
p1_ctotal = p1_ctotal - bid6
bid_pool = bid6 * 3 + bid_pool
print("bid pool is now", bid_pool)
if is_p1_folded == False:
foldyn = input(f"you've lost {bid_pool / 3}, your cards are {card1} and {card2}, and the flop is {flop_card1}, {flop_card2}, {flop_card3}, and {turn_card} fold Y/N? ")
if any(word in foldyn for word in keywords1):
print("p1 folded!")
is_p1_folded = True
else:
print("p1 stands")
p_bid = input("bid 10 20 30 40 50 60 70 80 or 90 ")
intp_bid = int(p_bid)
bid_pool = intp_bid * 3 + bid_pool
print("bid pool is now", bid_pool)
p1_ctotal = p1_ctotal - intp_bid
if is_p1_folded == True:
if is_npc1_folded == True:
print(f"jeff2 won! {bid_pool} chips! " )
sys.exit()
if is_p1_folded == True:
if is_npc2_folded == True:
print(f"jeff won! {bid_pool} chips! " )
sys.exit()
Maybe the question is due to this variable name. It might be bid_6, or the code bi6 = bid_6 * 10 wrong. Is what the exception is NameError?
Moreover, just using if-elif-else may not the right choice to express the logic for game. Maybe using class, def to repeat same codes and save some information is better.
While I am busy at the moment of writing this email I will be sure to check this thank you