21点代码python_21点代码python_在Python中实现21点

我正在为python编写一个21点代码,我希望有人能告诉我如何实现它:识别某人输入的内容,即“击中”或“站立”,并做出相应的反应。

计算出玩家的得分是多少,它是否是一张王牌和一个杰克在一起,并自动获胜。

好吧,这就是我到目前为止得到的。"This imports the random object into Python, it allows it to generate random numbers."

import random

print("Hello and welcome to Sam's Black Jack!")

input("Press to begin.")

card1name = 1

card2name = 1

card3name = 1

card4name = 1

card5name = 1

"This defines the values of the character cards."

Ace = 1

Jack = 10

Queen = 10

King = 10

decision = 0

"This generates the cards that are in your hand and the dealer's hand to begin with.

card1 = int(random.randrange(12) + 1)

card2 = int(random.randrange(12) + 1)

card3 = int(random.randrange(12) + 1)

card4 = int(random.randrange(12) + 1)

card5 = int(random.randrange(12) + 1)

total1 = card1 + card2

"This makes the value of the Ace equal 11 if the total of your cards is under 21"

if total1 <= 21:

Ace = 11

"This defines what the cards are"

if card1 == 11:

card1 = 10

card1name = "Jack"

if card1 == 12:

card1 = 10

card1name = "Queen"

if card1 == 13:

card1 = 10

card1name = "King"

if card1 == 1:

card1 = Ace

card1name = "Ace"

elif card1:

card1name = card1

if card2 == 11:

card2 = 10

card2name = "Jack"

if card2 == 12:

card2 = 10

card2name = "Queen"

if card2 == 13:

card2 = 10

card2name = "King"

if card2 == 1:

card2 = Ace

card2name = "Ace"

elif card2:

card2name = card2

if card3 == 11:

card3 = 10

card3name = "Jack"

if card3 == 12:

card3 = 10

card3name = "Queen"

if card3 == 13:

card3 = 10

card3name= "King"

if card3 == 1:

card3 = Ace

card3name = "Ace"

elif card3:

card3name = card3

if card4 == 11:

card4 = 10

card4name = "Jack"

if card4 == 12:

card4 = 10

card4name = "Queen"

if card4 == 13:

card4 = 10

card4name = "King"

if card4 == 1:

card4 = Ace

card4name = "Ace"

elif card4:

card4name = card4

if card5 == 11:

card5 = 10

card5name = "Jack"

if card5 == 12:

card5 = 10

card5name = "Queen"

if card5 == 13:

card5 = 10

card5name = "King"

if card5 == 1:

card5 = Ace

card5name = "Ace"

elif card5:

card5name = card5

"This creates the totals of your hand"

total2 = card1 + card2

total3 = card1 + card2 + card3

print("You hand is ", card1name," and", card2name)

print("The total of your hand is", total2)

decision = input("Do you want to HIT or STAND?").lower()

"This is the decision for Hit or Stand"

if 'hit' or 'HIT' or 'Hit' in decision:

decision = 1

print("You have selected HIT")

print("Your hand is ", card1name,",",card2name," and", card3name)

print("The total of your hand is", total3)

if 'STAND' or 'stand' or 'Stand' in decision:

print("You have selected STAND")

"Dealer's Hand"

dealer = card4 + card5

print()

print("The dealer's hand is", card4name," and", card5name)

if decision == 1 and dealer < total3:

print("Congratulations, you beat the dealer!")

if decision == 1 and dealer > total3:

print("Too bad, the dealer beat you!")

好吧,别客气,我把它修好了:D

我刚把目标改成是或否if total2 < 21:

decision = input("Do you want to hit? (Yes or No)")

"This is the decision for Hit or Stand"

if decision == 'Yes':

print("You have selected HIT")

print("Your hand is ", card1name,",",card2name," and", card3name)

print("The total of your hand is", total3)

if decision == 'No':

print("You have selected STAND")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值