我有两个关于while循环的问题!我不想浪费你的时间,但我真的需要帮助。
1,在我的代码中,while true: 还有一个 while 存在。我知道我可以打破第二个while循环,但我怎样才能同时打破第一个while循环?
2,在代码“if stand_hit == 'h'; 的末尾有没有回到stand_hit == 's'?我不希望它在通过stand_hit == h 后显示打印(mycard)的东西。我愿意想拿起新卡或立即站立。
谢谢!如果您对我的问题没有意义,请发表评论!
while True:
player_card = []
player_card.append(player_draw())
player_card.append(player_draw())
print('your cards:',player_card[0]+player_color,player_card[1]+player_color)
player_total = card_dict[player_card[0]]+card_dict[player_card[1]]
dealer_card = []
dealer_card.append(dealer_draw())
dealer_card.append(dealer_draw())
dealer_cards = []
for i in dealer_card:
dealer_cards.append(card_dict[i])
dealer_total = sum(dealer_cards)
player_card = []
stand_hit = input('(S)tand or (H)it?...: ')
if stand_hit == 's':
print('Dealer cards:', dealer_card[0]+dealer_color, dealer_card[1]+dealer_color)
while dealer_total < 17:
if dealer_total < 11:
card_dict['A'] = 11
elif dealer_total > 10:
card_dict['A'] = 1
a = random.choice(list(card_dict))
print('Dealer drew:', a + dealer_color)
dealer_total += card_dict[a]
if dealer_total > 21:
print('You win!')
player_score += 1
print('Dealer:', dealer_score, 'Player:', player_score)
play_again = input('Play again (Y/N)?...: ')
if play_again == 'y':
print()
continue
elif play_again == 'n':
print('\n')
print('>_')
break
蝴蝶不菲
相关分类