我想循环我的扑克计划10次,看看该计划赚了多少钱。这是我得到的输出然后我必须再次运行它,但该程序不会提醒上一轮赚取的金额。你们有什么建议吗?
Dealer has:
D9
Player1, you have:
['HK', 'DQ']
The amount of money player has won so far
0
What would you like to do? H: Hit me, S: Stand? S
Player wins with 20points
Dealer Busted and has: ['D9', 'C3', 'S5']or17points
Player has won : 2euros
处理完成,退出代码为0
我想在底部有一个额外的行与Total赚钱,程序再问我一个问题,如果我想再做一次。 我应该从哪里开始?
代码
from random import shuffle
def card():
card = []
for speci in ['H', 'D', 'S', 'C']:
for number in ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']:
card.append(speci+number)
shuffle(card)
return card
def pointcount(mycards):
counting = 0
acecount = 0
for i in mycards:
if(i[1] == 'J' or i[1] == 'Q' or i[1] == 'K' or i[1] == 'T'):
counting += 10
elif(i[1] != 'A'):
counting += int(i[1])
else:
acecount += 1
if(acecount == 1 and counting >= 10):
counting += 11
elif(acecount != 0):
counting += 1
return counting
def createplayinghands(mydeck):
dealerhand = []
playerhand = []
dealerhand.append(mydeck.pop())
dealerhand.append(mydeck.pop())
playerhand.append(mydeck.pop())
playerhand.append(mydeck.pop())
while(pointcount(dealerhand) <= 16):
dealerhand.append(mydeck.pop())
return [dealerhand, playerhand]
game = ""
mycard = card()
hands = createplayinghands(mycard)
dealer = hands[0]
player = hands[1]
money = 0
while(game != "exit"):
dealercount = pointcount(dealer)
playercount = pointcount(player)
print("Dealer has:")
print(dealer[0])
print("Player1, you have:")
print(player)
print("The amount of money player has won so far")
print(money)
if(playercount == 21):
money += 3
print("Blackjack Player wins")
print("Player has won: " + str(money) + "euros")
break
elif(playercount > 21):
money += 0
print("player Busts with " + str(playercount) + "points")
print("Player has won: " + str(money) + "euros")
break
elif(dealercount > 21):
print("Dealer Busts with " + str(dealercount) + "points")
print("Player has won: " + str(money) + "euros")
break
game = input("What would you like to do? H: Hit me, S: Stand? ")
if(game == 'H'):
player.append(mycard.pop())
elif(dealercount > 21):
money += 2
print("Player wins with " + str(playercount) + "points")
print("Dealer has: " + str(dealer) + "or" + str(dealercount) + "points")
print("Player has won : " + str(money) + "euros")
break
elif(playercount > dealercount):
money += 2
print("Player wins with " + str(playercount) + "points")
print("Dealer Busted and has: " + str(dealer) + "or" + str(dealercount) + "points")
print("Player has won : " + str(money) + "euros")
break
elif(playercount == dealercount):
money += 2
print("Tie Player with " + str(playercount) + "points")
print("Dealer has: " + str(dealer) + " or " + str(dealercount) + "poi nts")
print("Player has won : " + str(money) + "euros")
break
else:
money += 0
print("Dealer wins")
print("Dealer has: " + str(dealer) + "or" + str(dealercount) + "points")
print("Player has won : " + str(money) + "euros")
break
答案 0 :(得分:0)
如果您希望在每break
if-loop
if dealercount > 21:
money = money + 2
print("Player wins with " + str(playercount) + "points")
print("Dealer has: " + str(dealer) + "or" + str(dealercount) + "points")
print("Player has won : " + str(money) + "euros")
# break <----- breaking out of your while loop
答案 1 :(得分:0)
你在每只手的末尾打破,迫使你离开循环。如果删除break命令,它将循环并返回到开始。删除休息后,您需要说
if (game != 'H'):
# This loop was not a "Hit Me"
game = input("What would you like to do? Deal or exit? ")
由于您在游戏中阅读后没有计算卡数,因此您也会得到错误的计数值。
您需要将代码重做为
计算交易的初始分数
决定是站立还是点击
让经销商决定是站立还是击中。
决定手牌是否结束
如果手牌结束,请将结果添加到获胜者的钱中(和/或从输家中扣除)
如果手牌结束,请询问是否处理或退出
如果选择是交易,请回到开头
如果手还没有结束,请返回第2步