我的Black Jack代码非常基本,但运行得非常顺利,但是我遇到了一个减速带。我就在这里。当我打电话给#34; Hit"在我的While循环中向我发送另一张卡片,对于每个循环,DECK实例化同一张卡片。前2张和Hit牌总是不同,但在While循环中(当玩家说"停留"并且不想要另一张牌时设置为结束。)Hit卡保持不变。
import random
import itertools
SUITS = 'cdhs'
RANKS = '23456789TJQKA'
DECK = tuple(''.join(card) for card in itertools.product(RANKS, SUITS))
hand = random.sample(DECK, 2)
hit = random.sample(DECK, 1)
print("Welcome to Jackpot Guesser! ")
c = input("Would you like to play Black Jack or play Slots? ")
if c == 'Black Jack':
print()
print("Welcome to Black Jack! Here are the rules: ")
print("Black Jack is a game of whit, skill with a bit of Luck. You will start with 2 card and try to achieve a total of 21 points. \n Each cards worth is equal to its number, face cards are worth 10 and the Ace can be 1 or 11 points. You decide. \n You can decide to -Stay- and take the points you have or -Hit- to get another card. If you get 21 its Black Jack and you win. \n If no one gets 21, the highest points win, but if you go over 21 you -Bomb- and lose everything. \n Becarful not to Bomb and goodluck out there! Remember, you got to know when to Hit, when to Stay and when to walk away! \n")
print(hand)
print()
g = 'swag'
while g != 'Stay':
g = input(("What would you like to do, Stay or Hit: "))
if g == 'Hit':
print(hit)
elif g == 'Stay':
print("Lets see how you did!")
else:
print("test3")
elif c == 'Slots':
print("test")
else:
print("test2")
EX:手:Td(两颗钻石),3c(3支球杆) 命中:7s(7个黑桃) 打7s 打7s 打7s ... 留下来:让我们看看你是怎么做的。我需要继续的While循环命中不同,任何想法。
答案 0 :(得分:1)
问题是你在程序启动期间只生成一次命中卡。从
更改代码 if g == 'Hit':
print(hit)
类似
if g == 'Hit':
hit = random.sample(DECK, 1)
print(hit)
会在每次点击时输出不同的卡片。