嘿,我正在努力在 Python 中为我的二十一点游戏添加投注,由于某种原因,我的代码现在不会首先通过 if 语句。任何帮助将不胜感激。
我的代码如下:
def play():
""" Function that involves all gameplay and allows the user to play blackjack. All
other functions are to support the gameplay while this function covers the actual
gameplay. """
#initializing a counter for how many times the user has played
global total_play_count
#total winnings of a player if they already played from last hand
global total_winnings
if total_play_count == 0:
play_count = 0
else:
play_count = total_play_count
#setting a variable to hold the users total cash
if play_count == 0:
winnings = 100
else:
winnings = total_winnings
#dealing user and dealer their cards
global user_show_cards
global dealer_show_cards
user_show_cards = [card(), card()]
dealer_show_cards = [card(), card()]
#declaring total variables
global user_total
global dealer_total
user_total = 0
dealer_total = 0
#lists to hold numerical values of the hand
global user_total_cards
global dealer_total_cards
user_total_cards = []
dealer_total_cards = []
#initializing the values of cards and storing them in the lists above
user_total_cards = ready_for_total(user_show_cards, user_total_cards, user_total)
dealer_total_cards = ready_for_total(dealer_show_cards, dealer_total_cards, dealer_total)
#getting initial player totals
user_total = sum(user_total_cards)
dealer_total = sum(dealer_total_cards)
#printing what is initially shown on screen
print ""
print "Let's play Blackjack"
print "Note: Dealer stays on ALL 17s"
print ""
if play_count == 0:
print "You start with $100"
else:
pass
bet = int(raw_input("Enter your bet: "))
winnings -= bet
print ""
print "You now have $%s" %(winnings)
print ""
print "Your cards are %s %s" %(str(user_show_cards[0]), str(user_show_cards[1]))
print "The dealer's up card is a(n) %s" %(str(dealer_show_cards[0]))
代码不会通过上面的行
#first condition to see if the player has Blackjack
if user_total == 21:
print "Blackjack! You Win!"
bet1 = bet * 2
print "You receive $%s" %(bet1)
winnings += bet + bet1
print "Your winnings now total $%s" %(str(winnings))
elif dealer_total == 21:
print "Dealer got Blackjack. You lose."
print ""
print "You now have $%s" %(winnings)
else:
total_winnings = winnings
return total_winnings
hit_or_stay()
print ""
play_again = raw_input("Play again? (y/n): ")
if play_again == "y":
total_winnings = winnings
play_count += 1
total_play_count = play_count
play()
return total_play_count
return total_winnings
else:
print ""
print "Your winnings totaled $%s" %(winnings)
print "Goodbye, come back soon!"
play()