Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

First Time Python Program

bongoman1000bongoman1000 Posts: 1Member
Hi guys, I'm 13 years old, and this is my first Python program. I just want some constructive criticism. It is a Blackjack game. Enjoy!

[code]#Blackjack Game
import random
card = 0
player = 1
count1 = 0
count2 = 0
menu_choice = 1
player_pool = 100
loop_decider = 1
loop_decider1 = 1
loop_decider2 = 1
loop_decider3 = 1
loop_decider4 = 1
loop_decider5 = 1
loop_decider6 = 1
loop_decider7 = 1
def reset_cards():
deck = ['2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', '10h', 'jh', 'qh', 'kh', 'ah', '2c',
'3c', '4c', '5c', '6c', '7c', '8c', '9c', '10c', 'jc', 'qc', 'kc', 'ac', '2s', '3s',
'4s', '5s', '6s', '7s', '8s', '9s', '10s', 'js', 'qs', 'ks', 'as', '2d', '3d', '4d', '5d', '6d', '7d', '8d',
'9d', '10d', 'jd', 'qd', 'kd', 'ad']
random.shuffle(deck)
return deck
deck = reset_cards()
def print_menu():
print "Play the game. [1]"
print "Learn the Rules. [2]"
print "See the Credits. [3]"
print "Quit the Game. [4]"
def card_identify(player):
card = deck[0]
if player == 1:
if card == '2h':
print "You got the Two of Hearts."
elif card == '3h':
print "You got the Three of Hearts."
elif card == '4h':
print "You got the Four of Hearts."
elif card == '5h':
print "You got the Five of Hearts."
elif card == '6h':
print "You got the Six of Hearts."
elif card == '7h':
print "You got the Seven of Hearts."
elif card == '8h':
print "You got the Eight of Hearts."
elif card == '9h':
print "You got the Nine of Hearts."
elif card == '10h':
print "You got the Ten of Hearts."
elif card == 'jh':
print "You got the Jack of Hearts."
elif card == 'qh':
print "You got the Queen of Hearts."
elif card == 'kh':
print "You got the King of Hearts."
elif card == 'ah':
print "You got the Ace of Hearts."
elif card == '2c':
print "You got the Two of Clubs."
elif card == '3c':
print "You got the Three of Clubs."
elif card == '4c':
print "You got the Four of Clubs."
elif card == '5c':
print "You got the Five of Clubs."
elif card == '6c':
print "You got the Six of Clubs."
elif card == '7c':
print "You got the Seven of Clubs."
elif card == '8c':
print "You got the Eight of Clubs."
elif card == '9c':
print "You got the Nine of Clubs."
elif card == '10c':
print "You got the Ten of Clubs."
elif card == 'jc':
print "You got the Jack of Clubs."
elif card == 'qc':
print "You got the Queen of Clubs."
elif card == 'kc':
print "You got the King of Clubs."
elif card == 'ac':
print "You got the Ace of Clubs."
elif card == '2s':
print "You got the Two of Spades."
elif card == '3s':
print "You got the Three of Spades."
elif card == '4s':
print "You got the Four of Spades."
elif card == '5s':
print "You got the Five of Spades."
elif card == '6s':
print "You got the Six of Spades."
elif card == '7s':
print "You got the Seven of Spades."
elif card == '8s':
print "You got the Eight of Spades."
elif card == '9s':
print "You got the Nine of Spades."
elif card == '10s':
print "You got the Ten of Spades."
elif card == 'js':
print "You got the Jack of Spades."
elif card == 'qs':
print "You got the Queen of Spades."
elif card == 'ks':
print "You got the Queen of Spades."
elif card == 'as':
print "You got the Ace of Spades."
elif card == '2d':
print "You got the Two of Diamonds."
elif card == '3d':
print "You got the Three of Diamonds."
elif card == '4d':
print "You got the Four of Diamonds."
elif card == '5d':
print "You got the Five of Diamonds."
elif card == '6d':
print "You got the Six of Diamonds."
elif card == '7d':
print "You got the Seven of Diamonds."
elif card == '8d':
print "You got the Eight of Diamonds."
elif card == '9d':
print "You got the Nine of Diamonds."
elif card == '10d':
print "You got the Ten of Diamonds."
elif card == 'jd':
print "You got the Jack of Diamonds."
elif card == 'qd':
print "You got the Queen of Diamonds."
elif card == 'kd':
print "You got the King of Diamonds."
elif card == 'ad':
print "You got the Ace of Diamonds."
return card
def hit(player_count, card):
card = deck[0]
def ace(player_count):
player_count = 11 + player_count
if player_count > 21:
player_count = player_count - 11
card = 1
elif player_count <= 21:
player_count = player_count - 11
card = 11
return card
if card == '2h':
card = 2
elif card == '3h':
card = 3
elif card == '4h':
card = 4
elif card == '5h':
card = 5
elif card == '6h':
card = 6
elif card == '7h':
card = 7
elif card == '8h':
card = 8
elif card == '9h':
card = 9
elif card == '10h':
card = 10
elif card == 'jh':
card = 10
elif card == 'qh':
card = 10
elif card == 'kh':
card = 10
elif card == 'ah':
card = ace(count1)
elif card == '2c':
card = 2
elif card == '3c':
card = 3
elif card == '4c':
card = 4
elif card == '5c':
card = 5
elif card == '6c':
card = 6
elif card == '7c':
card = 7
elif card == '8c':
card = 8
elif card == '9c':
card = 9
elif card == '10c':
card = 10
elif card == 'jc':
card = 10
elif card == 'qc':
card = 10
elif card == 'kc':
card = 10
elif card == 'ac':
card = ace(count1)
elif card == '2s':
card = 2
elif card == '3s':
card = 3
elif card == '4s':
card = 4
elif card == '5s':
card = 5
elif card == '6s':
card = 6
elif card == '7s':
card = 7
elif card == '8s':
card = 8
elif card == '9s':
card = 9
elif card == '10s':
card = 10
elif card == 'js':
card = 10
elif card == 'qs':
card = 10
elif card == 'ks':
card = 10
elif card == 'as':
card = ace(count1)
elif card == '2d':
card = 2
elif card == '3d':
card = 3
elif card == '4d':
card = 4
elif card == '5d':
card = 5
elif card == '6d':
card = 6
elif card == '7d':
card = 7
elif card == '8d':
card = 8
elif card == '9d':
card = 9
elif card == '10d':
card = 10
elif card == 'jd':
card = 10
elif card == 'qd':
card = 10
elif card == 'kd':
card = 10
elif card == 'ad':
card = ace(count1)
del deck[0]
return card
def game_menu():
print "Would you like to hit, or stay?"
print "Hit [1]"
print "Stay [2]"
while menu_choice != 4:
deck = reset_cards()
print "Welcome to Blackjack! Please make a selection."
player_pool = 100
print_menu()
menu_choice = input("What is your selection? ")
if menu_choice == 42:
print "The answer to life, the universe, and everything."
elif menu_choice == 17:
print "You found the most secret easter egg in the whole game. You now start with $1,000,000."
player_pool = 1000000
menu_choice = 1
while menu_choice == 1:
deck = reset_cards()
loop_decider = 1
loop_decider1 = 1
loop_decider2 = 1
loop_decider3 = 1
loop_decider4 = 1
loop_decider5 = 1
loop_decider6 = 1
loop_decider7 = 1
reset_cards()
count1 = 0
count2 = 0
print "Let's Play Blackjack!"
print "You have ", player_pool, " dollars."
if player_pool <= 0:
print "You have no money left. You cannot play."
break
while loop_decider6 != 0:
bet = input("What is your bet? ")
if bet > player_pool:
print "Your bet cannot be higher than the amount of money you own."
elif bet < 0:
print "You cannot bet a negative amount."
else:
loop_decider6 = 0
card_identify(1)
count1 = hit(count1, card)
print "and"
card_identify(1)
count1 = count1 + hit(count1, card)
print "Your starting card total is: ",
print count1
card_identify(2)
count2 = hit(count2, card)
card_identify(2)
count2 = count2 + hit(count2, card)
if count1 == 21:
print "You got Blackjack!"
if count1 == count2:
print "You tied!"
menu_choice = 5
elif count1 > count2:
print "You win!"
player_pool = player_pool + (bet/2) * 3
print "You now have ", player_pool, " dollars."
while loop_decider2 != 0:
print "Would you like to go for another round?"
print "Yes [1]"
print "No [2]"
play_again4 = input("Choice: ")
if play_again4 == 1:
loop_decider = 0
loop_decider2 = 0
elif play_again4 == 2:
menu_choice = 5
loop_decider2 = 0
break
else:
print "That is not a choice."
while loop_decider != 0:
game_menu()
game_menu_choice = input("What is your choice? ")
if game_menu_choice == 1:
card_identify(1)
count1 = count1 + hit(count1, card)
print "Your total so far is: ",
print count1
if count1 == 21:
print "You got Blackjack!"
if count1 == count2:
print "You tied!"
menu_choice = 5
break
elif count1 > count2:
print "You win!"
player_pool = player_pool + bet
print "You now have ", player_pool, " dollars."
while loop_decider1 != 0:
print "Would you like to go for another round?"
print "Yes [1]"
print "No [2]"
play_again5 = input("Choice: ")
if play_again5 == 1:
loop_decider1 = 0
loop_decider = 0
elif play_again5 == 2:
menu_choice = 5
loop_decider = 0
loop_decider1 = 0
break
else:
print "That is not a choice."
elif count1 > 21:
print "Busted!"
print "GAME OVER"
print "You now have ",
print player_pool - bet,
print " dollars."
player_pool = player_pool - bet
while loop_decider3 != 0:
print "Would you like to go for another round?"
print "Yes [1]"
print "No [2]"
play_again = input("Choice: ")
if play_again == 1:
loop_decider = 0
loop_decider3 = 0
elif play_again == 2:
menu_choice = 5
loop_decider3 = 0
loop_decider = 0
break
else:
print "That is not a choice."

if game_menu_choice == 2:
print "Your final total is: ",
print count1
print "Now let's compare your total to the dealer's."
raw_input("Press enter to continue...")
print "The dealer's total is: ",
print count2
if count1 < count2:
print "You lose."
print "GAME OVER"
print "You now have ",
print player_pool - bet,
print " dollars."
player_pool = player_pool - bet
while loop_decider4 != 0:
print "Would you like to go for another round?"
print "Yes [1]"
print "No [2]"
play_again2 = input("Choice: ")
if play_again2 == 1:
loop_decider = 0
loop_decider4 = 0
elif play_again2 == 2:
menu_choice = 5
loop_decider4 = 0
loop_decider = 0
break
else:
print "That is not a choice."
elif count1 > count2:
print "You win!"
print "GAME OVER"
print "You now have ",
print player_pool + bet,
print " dollars."
player_pool = player_pool + bet
while loop_decider7 != 0:
print "Would you like to go for another round?"
print "Yes [1]"
print "No [2]"
play_again3 = input("Choice: ")
if play_again3 == 1:
loop_decider = 0
loop_decider7 = 0
elif play_again3 == 2:
menu_choice = 5
loop_decider = 0
loop_decider7 = 0
break
else:
print "That is not a choice."
elif count1 == count2:
print "You tied!"
print "You now have ", player_pool, " dollars."
while loop_decider5 != 0:
print "Would you like to go for another round?"
print "Yes [1]"
print "No [2]"
play_again6 = input("Choice: ")
if play_again6 == 1:
loop_decider = 0
loop_decider5 = 0
elif play_again6 == 2:
menu_choice = 5
loop_decider5 = 0
loop_decider = 0
break
else:
print "That is not a choice."
if menu_choice == 2:
print """The rules of Blackjack are simple. Try to have your cards total value be"""
print """greater than the dealer's without going over 21. Each turn, you can either "hit" """
print """which means take another card, or "stay,"which means not take anymore cards and end"""
print """the game. If your value is higher than the dealer's, you win, and collect your"""
print """betted money. If your value is lower, you lose your bet. If it's the same, it is a tie,"""
print """and you don't earn or lose any money. The values of the cards are as follows:"""
print """Number cards are face value. Jacks, Queens, and Kings are each worth 10. An Ace is"""
print """either worth 1, or 11, depending on which one would help you more. Have fun playing Blackjack!"""
raw_input("Press enter to continue...")
if menu_choice == 3:
print "Head Developer: Alexis Geoffrey"
print "Head Coder: Alexis Geoffrey"
print "Idea by: Alexis Geoffrey"
print "Pathetic Productions Gaming Copyright 2010"
raw_input("Press enter to continue...")
[/code]
Sign In or Register to comment.