Hi All,
I believe I am following the rules for this sub, but please remove or comment if I need to take this elsewhere/if this needs to be taken down. I am about 3-4 months into my consistent Python journey, and have been dabbling for about a year and a half total. Being stuck in tutorial hell for the last few weeks, I finally decided to take the advice of “Just. Start. Building.” After taking a look at another post and recognizing that “Tech with Tim” had some good starter projects, I decided to do Blackjack. This is a rough, rough, rough draft of what I have so far, and I’d like to ask for feedback from folks on this thread. Appreciate you all, and I have already learned a ton from the brain trust in the sub. Just want to make sure I’m implementing best practices and, if I’m not, nipping that in the bud to get there. See below:
import random player_hand = random .randint(1, 12) dealer_hand = random .randint(1, 12) + random .randint(1, 12) def card_calculation(player_hand, dealer_hand): if player_hand > 21: print(f"Your Hand: {player_hand}") print("BUST! You lose.") elif dealer_hand > 21: print(f"Dealer's Hand: {dealer_hand}") print(f"Your Hand: {player_hand}") print("DEALER BUST! You win!") elif player_hand == 21: print(f"Dealer's Hand: {dealer_hand}") print(f"Your Hand: {player_hand}") print('BLACKJACK! You win.') elif dealer_hand > player_hand: print(f"Dealer's Hand: {dealer_hand}") print(f"Your Hand: {player_hand}") print('Dealer has a higher hand. You lose.') elif dealer_hand == player_hand: print(f"Dealer's Hand: {dealer_hand}") print(f"Your Hand: {player_hand}") print('You and the dealer have the same sum of cards. This is a push.') elif dealer_hand < player_hand: print('You win!') print("Welcome to JT's Blackjack Table!") print(f"You're starting with {player_hand}.") while player_hand < 21: player_action = input("Hit or Stand?") if player_action == "Hit": player_hand += random .randint(1, 12) print(player_hand) elif player_action == "Stand": break card_calculation(player_hand, dealer_hand)
A few notes I already have of my own:
- I feel like I could add in a ‘want to play again?’ input Q at the end of the program.
- I believe there are some more granular rules with when the dealer hits/when they don’t (forgive me for not knowing, but maybe 16 is the determining factor? Or 17?). I could bake in this logic.
What am I not thinking about?
submitted by /u/YaeTee
[link] [comments]
r/learnpython Hi All, I believe I am following the rules for this sub, but please remove or comment if I need to take this elsewhere/if this needs to be taken down. I am about 3-4 months into my consistent Python journey, and have been dabbling for about a year and a half total. Being stuck in tutorial hell for the last few weeks, I finally decided to take the advice of “Just. Start. Building.” After taking a look at another post and recognizing that “Tech with Tim” had some good starter projects, I decided to do Blackjack. This is a rough, rough, rough draft of what I have so far, and I’d like to ask for feedback from folks on this thread. Appreciate you all, and I have already learned a ton from the brain trust in the sub. Just want to make sure I’m implementing best practices and, if I’m not, nipping that in the bud to get there. See below: import random player_hand = random .randint(1, 12) dealer_hand = random .randint(1, 12) + random .randint(1, 12) def card_calculation(player_hand, dealer_hand): if player_hand > 21: print(f”Your Hand: {player_hand}”) print(“BUST! You lose.”) elif dealer_hand > 21: print(f”Dealer’s Hand: {dealer_hand}”) print(f”Your Hand: {player_hand}”) print(“DEALER BUST! You win!”) elif player_hand == 21: print(f”Dealer’s Hand: {dealer_hand}”) print(f”Your Hand: {player_hand}”) print(‘BLACKJACK! You win.’) elif dealer_hand > player_hand: print(f”Dealer’s Hand: {dealer_hand}”) print(f”Your Hand: {player_hand}”) print(‘Dealer has a higher hand. You lose.’) elif dealer_hand == player_hand: print(f”Dealer’s Hand: {dealer_hand}”) print(f”Your Hand: {player_hand}”) print(‘You and the dealer have the same sum of cards. This is a push.’) elif dealer_hand < player_hand: print(‘You win!’) print(“Welcome to JT’s Blackjack Table!”) print(f”You’re starting with {player_hand}.”) while player_hand < 21: player_action = input(“Hit or Stand?”) if player_action == “Hit”: player_hand += random .randint(1, 12) print(player_hand) elif player_action == “Stand”: break card_calculation(player_hand, dealer_hand) A few notes I already have of my own: I feel like I could add in a ‘want to play again?’ input Q at the end of the program. I believe there are some more granular rules with when the dealer hits/when they don’t (forgive me for not knowing, but maybe 16 is the determining factor? Or 17?). I could bake in this logic. What am I not thinking about? submitted by /u/YaeTee [link] [comments]
Hi All,
I believe I am following the rules for this sub, but please remove or comment if I need to take this elsewhere/if this needs to be taken down. I am about 3-4 months into my consistent Python journey, and have been dabbling for about a year and a half total. Being stuck in tutorial hell for the last few weeks, I finally decided to take the advice of “Just. Start. Building.” After taking a look at another post and recognizing that “Tech with Tim” had some good starter projects, I decided to do Blackjack. This is a rough, rough, rough draft of what I have so far, and I’d like to ask for feedback from folks on this thread. Appreciate you all, and I have already learned a ton from the brain trust in the sub. Just want to make sure I’m implementing best practices and, if I’m not, nipping that in the bud to get there. See below:
import random player_hand = random .randint(1, 12) dealer_hand = random .randint(1, 12) + random .randint(1, 12) def card_calculation(player_hand, dealer_hand): if player_hand > 21: print(f"Your Hand: {player_hand}") print("BUST! You lose.") elif dealer_hand > 21: print(f"Dealer's Hand: {dealer_hand}") print(f"Your Hand: {player_hand}") print("DEALER BUST! You win!") elif player_hand == 21: print(f"Dealer's Hand: {dealer_hand}") print(f"Your Hand: {player_hand}") print('BLACKJACK! You win.') elif dealer_hand > player_hand: print(f"Dealer's Hand: {dealer_hand}") print(f"Your Hand: {player_hand}") print('Dealer has a higher hand. You lose.') elif dealer_hand == player_hand: print(f"Dealer's Hand: {dealer_hand}") print(f"Your Hand: {player_hand}") print('You and the dealer have the same sum of cards. This is a push.') elif dealer_hand < player_hand: print('You win!') print("Welcome to JT's Blackjack Table!") print(f"You're starting with {player_hand}.") while player_hand < 21: player_action = input("Hit or Stand?") if player_action == "Hit": player_hand += random .randint(1, 12) print(player_hand) elif player_action == "Stand": break card_calculation(player_hand, dealer_hand)
A few notes I already have of my own:
- I feel like I could add in a ‘want to play again?’ input Q at the end of the program.
- I believe there are some more granular rules with when the dealer hits/when they don’t (forgive me for not knowing, but maybe 16 is the determining factor? Or 17?). I could bake in this logic.
What am I not thinking about?
submitted by /u/YaeTee
[link] [comments]