import random
# This is BlackJack.
Player = raw_input("Enter your name here.")
print
class special_card(object):
print "The three face cards have different values."
print "The Ace Card can also be 1 or 11."
def __init__(self, face_name, value):
self.face_name = face_name
self.value = value
king_card = special_card("King", 13)
print king_card.face_name
print king_card.value
queen_card = special_card("Queen", 12)
print queen_card.face_name
print queen_card.value
jack_card = special_card("Jack", 11)
print jack_card.face_name
print jack_card.value
default_cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11]
guide = ("BlackJack also known as 21 is a simple card game. All normal cards such as 2,3,4... have that value. Cards such as the ace or the face cards have different values as stated above. You cannot split if you have two aces.")
def enter():
print "Welcome to the Table."
answer = raw_input("Do you want to sit down and begin playing? Type 'yes' to play. Type 'no' if you would like to leave. Type 'help' if you want to know the rules.").lower()
if answer == "yes":
print "Let's get started."
elif answer == "help":
return guide
elif answer == "no":
exit = raw_input("Are you sure? (Type yes): ")
if "yes" in exit:
return None
enter()
def total(hand):
ace = hand.count(11)
tot = sum(hand)
if tot > 21 and ace > 0:
while ace > 0 and tot > 21:
tot -= 10
ace -= 1
return tot
yourbust = False
dealerbust = False
while True:
print
print "Dealing Cards..."
# This will draw two cards for you.
you = []
you.append(random.choice(default_cards))
you.append(random.choice(default_cards))
while True:
# Now this is your hand after drawing those two cards.
toty = total(you)
print "Your cards are %s, and those two equal %d" % (you, toty)
if toty > 21:
print "I have bad luck. Went over 21."
break
elif toty == 21:
print "I win! I got exactly 21!"
break
else:
hit_stand = raw_input("Type 'hit' to get another card. Else press enter to stand.")
if "hit" in hit_stand:
you.append(random.choice(default_cards))
else:
break
while True:
print
print "Dealing Cards..."
# Dealer will draw two cards for their self."
dealer = []
dealer.append(random.choice(default_cards))
dealer.append(random.choice(default_cards))
while True:
totd = total(dealer)
if totd < 15:
""" This will force dealer to add another card """
dealer.append(random.choice(default_cards))
else:
break
print "Dealer's cards are %s, and those two equal %d" % (dealer, totd)
# The code below will determine who will win. Total(you) vs. total(dealer)
if totd > 21:
print "The dealer loses and you win. They had gone over 21."
dealerbust = True
if youbust == False:
print "%s wins." % (Player)
elif totd > toty:
print "The dealer wins and you lose."
elif toty > totd:
if toty == False:
print "I have a higher total than the dealer!"
elif totd == False:
print "The dealer has a higher total than you!"
break
print
exit = raw_input("Would you like to try again? (Press Enter to play again, or type 'quit' to leave the table): ")
if "quit" in exit:
break
print
print "Thank you for trying out my game."
我一直在第37行elif回答==&#34; help&#34;:语法无效 引导变量是否合适?当有人帮忙时,我希望它回归到那个。
由于某种原因,它在一秒钟前随机工作。然后它继续给我更多的错误与那种缩进。 我不知道如何解决它。
编辑: 这就是我得到的
Enter your name here. KJ
The three face cards have different values.
The Ace Card can also be 1 or 11.
King
13
Queen
12
Jack
11
Welcome to the Table.
Do you want to sit down and begin playing? Type 'yes' to play. Type 'no' if you would like to leave. Type 'help' if you want to know the rules. help
Traceback (most recent call last):
File "python", line 69, in <module>
TypeError: %d format: a number is required, not NoneType