why does my terminal say Dealer had<function revealdealerhand at 0x00000244ABB568C0> and X but my hand is normal?
@user-by4uv2hl5uАй бұрын
this is the code that i use : def revealdealerhand(): if len(dealerhand) == 2: return dealerhand [0] elif len(dealerhand) > 2: return dealerhand [0], dealerhand[1]
@Piktro2 ай бұрын
I'm brand new to Python, haven't touched any code in 10+ years until 2 weeks ago, but wouldn't it be easier to check certain win conditions during each turn, or at least print the player and dealer hands at the end outside of the if statements, to avoid repeating all that code and all those print statements? For example, immediately after dealing: If player and dealer blackjack, print push. Elif player blackjack, print player wins. Elif dealer blackjack, print dealer wins. In player turn: If player busts, print dealer wins In dealer turn: If dealer busts, print player wins. Then after a player "stand", just compare player vs dealer totals. If player > dealer, print player wins. Elif dealer > player, print dealer wins. Even if we keep the code how it is, wouldn't something like the following be much easier to read? print(f"Player has {total(player_hand)}. Dealer has {total(dealer_hand)}.") if total(player_hand) == 21: print(f"Blackjack, you win!") elif total(dealer_hand) == 21: print(f"Blackjack, dealer wins!") elif total(player_hand) > 21: print(f"Player bust! Dealer wins.") elif total(dealer_hand) > 21: print(f"Dealer bust! Player wins.") elif 21 - total(dealer_hand) < 21 - total(player_hand): print(f"You win!") elif 21 - total(dealer_hand) > 21 - total(player_hand): print(f"Dealer wins!") I've just watched a bunch of tutorials and things like "don't repeat yourself" were hammered into my brain.
@YashviDungrani2 ай бұрын
# i've tried solving all the problems like if wrong input, user won't switch and computer can't generate same numbers again and again.... # hope this helps import random # creating board board=[ "-", "-", "-", "-", "-", "-", "-", "-", "-"] livePlayer="X" win=None codeRunning=True # print board def prBoard(board): print(' '+board[0] +" | "+ board[1] +" | "+ board[2] ) print("-----------") print(' '+board[3] +" | "+ board[4] +" | "+ board[5] ) print("-----------") print(' '+board[6] +" | "+ board[7] +" | "+ board[8] ) # user(player1) input in board def userIn(board): u_in=int(input("Enter a number btwn 1-9: ")) if u_in >= 1 and u_in <= 9 and board[u_in-1] == '-': board[u_in-1] = livePlayer else: print("WRONG INPUT!!!! Try again...") switchPlayer() # computer(player2) input(random module) def computerIn(board): while livePlayer=='O': for i in board: c=random.randint(0,8) if c not in board and board[c]=='-': c_in=c break print(f"Computer's turn: {c_in+1}") board[c_in]='O' switchPlayer() checkwin() # switch player def switchPlayer(): global livePlayer if livePlayer=='X': livePlayer='O' else: livePlayer='X' # horizontal WIN ||| def rowWin(board): global win if board[0] == board[1] == board[2] and board[0] != '-': win=board[0] return True elif board[3] == board[4] == board[5] and board[3] != '-': win=board[3] return True elif board[6] == board[7] == board[8] and board[6] != '-': win=board[6] return True # vertical WIN --- def columnWin(board): global win if board[0] == board[3] == board[6] and board[0] != '-': win=board[0] return True elif board[1] == board[4] == board[7] and board[1] != '-': win=board[1] return True elif board[2] == board[5] == board[8] and board[2] != '-': win=board[2] return True # criss cross WIN \ / def crossWin(board): global win if board[0] == board[4] == board[8] and board[0] != '-': win=board[0] return True elif board[2] == board[4] == board[6] and board[2] != '-': win=board[2] return True # Tie def tie(board): if '-' not in board: prBoard(board) print("Its a Tie...") codeRunning=False # winning criteria (or tie) def checkwin(): global codeRunning if rowWin(board) or columnWin(board) or crossWin(board): prBoard(board) print(f"The winner is {win} :)") codeRunning=False # Main while codeRunning: prBoard(board) userIn(board) checkwin() tie(board) switchPlayer() computerIn(board) checkwin() tie(board)
@soumitakar43732 ай бұрын
Most simplest video on yt, Thanks a lot.
@aruneshrk75203 ай бұрын
Got the output but have some indentation error 😅.
@pavelpolosin22173 ай бұрын
I don't understand. How is possible to equal board[inp - 1] = current_player. But current_player variable is a string type, and inp - integer
@Aqua001_Ай бұрын
8:28 That [inp-1] is to find the index(Since the player input starts at 1 and the board index starts at 0 we sub the 1) after that we assign the player input to the board accourding to the index. Therefore it is Board[index] = playerInp.
@SlytherinLassie3 ай бұрын
I didn't understand the "board[inp-1]" thing in the function of playerInput.
@BoddepallliKeshavaKumar-qx6hp3 ай бұрын
very nice video, good explanation and well understood . Thank You
@i11usion3 ай бұрын
Thank you!
@skylorhamilton91513 ай бұрын
Oddly I'm getting "oops player is already in that spot when entering 1. 2-9 is cool though. There's a dash in the 1 position in the code just like 2-9. The computer is able to use position 1 though.
@user-vi5kg5ue3h3 ай бұрын
keep going bro
@zihanmubarak18903 ай бұрын
it's actually beginner friendly
@iwatchanime97893 ай бұрын
HELP great vid i copied it perfectly but im jw how do i get in the terminal mine isnt like urs also i cant run the program it says error "cant find __main__" i put this in a new file im 1 week into coding so i probably didnt do something very basic
@Contentbabyyy4 ай бұрын
13:51
@thanapalthanapal98384 ай бұрын
tnk u so much, it very helpful
@thanapalthanapal98384 ай бұрын
board[inp-1]=="-" this line i can't understand
@TortoiseEnjoyer4 ай бұрын
def revealDealerHand(): unindent does not match any outer indentation level :C
@ChorizoConHuevosEnTuBoca4 ай бұрын
It sucks cuz it doesn’t have true async
@katana65335 ай бұрын
wtf wrong w your voice?
@samatamotors22995 ай бұрын
Thank you so much life save!
@the_great_unknown15 ай бұрын
Can someone post the code plz need it for a project in my python class ain't tryna type allthat
@rommepomme133 ай бұрын
did u get it? pls post
@Misao.6 ай бұрын
your voice is attractive
@Das_086 ай бұрын
Hey your discord invite link is invalid
@gedtoon64516 ай бұрын
your game logic does not include both player and dealer have 21 or player and dealer are both bust.
@jammin13366 ай бұрын
This was my first project, i watched a hour long tutorial to learn then i spent 20 minutes making tic tac toe
@Gemini_mind6 ай бұрын
why are you whispering?
@jonathanhernandez59177 ай бұрын
Good explanation but that voice 😂
@jbx66 ай бұрын
Not cool to throw shame bro
@user-pu4eb7ew5g7 ай бұрын
Nice video thank you , only had to change it on playerInput , because if there was a "oops blablabla.." it would switch to the next player , so you can fill the rest of the grid with only O or only X if you want : def playerInput(board): while True: user_input = int(input("Enter a number 1-9: ")) if user_input >= 1 and user_input <=9 and board[user_input-1] == "-": board[user_input-1] = currentPlayer break else: print("Oops this place is already taken. Please pick a new numbers !") continue
@faizo0077 ай бұрын
Well Done!
@StraightAsPodcast7 ай бұрын
The audio and video don't match. The video is a few seconds faster than the audio.
@StraightAsPodcast7 ай бұрын
Nvm it was just my monitor.
@kodama71327 ай бұрын
so with this im finding that if you choose a spot that is already taken, it still switches currentPlayer variable and skips your turn
@Marci.K6 ай бұрын
You can fix this by removing switchPlayer() from the while cycle and put it in the playerInput under the if statement
@shyammohan-dd4oc7 ай бұрын
W
@omatamaneenyanga15867 ай бұрын
My python isn't showing the board and it Python 3.12.0
@sunitsawant8857 ай бұрын
Cant run it again please help
@adarabdulaev8 ай бұрын
Great tutorial
@frankstenner53778 ай бұрын
well made, thank you !
@cartoonmultiverse9068 ай бұрын
Is there an algorithm that allows the player to win randomly? However enjoyed your video and it was really helpful
@Frenk339 ай бұрын
I fucking hate flask
@PeppyHannah9 ай бұрын
This was really fun to do, thank you so much! Do you think you could possibly do some Python tutorials for complete beginners? The way you teach and explain what you're doing is the best and would love to see it in Python tutorials 😆
@Jammzz_balisong9 ай бұрын
the ace is 11 or 1
@Muhammad.Kashif3110 ай бұрын
share the source code plz
@Muhammad.Kashif3110 ай бұрын
incredible! where can i get the source code
@hgs14210 ай бұрын
Gosh his voice is so terrible I can't listen to it
@ricitos200110 ай бұрын
This video is very usefull because with this i ended my version of the game "BlackJack" I gave yo my like and my sub Thank you for help me
@berringervids10 ай бұрын
Totally noob at python, but why not use deck = [1,2,3....] and then do decks = deck*4?
@mrx-vx4wr10 ай бұрын
12:50 why the computer doesn't go straight for win?