我是Python和编码的新手。我想知道有人可以看看我需要更改的内容...
# Amount of chips player has
starting_chips = 1000
print('Player 1 has {}\n'.format(starting_chips))
# Amount of chips player wants to bet
try:
placed_bet = int(input('Place your bet: '))
except ValueError:
print("Sorry, I didn't understand that.")
continue
print('')
if placed_bet > starting_chips:
print("You don't have enough funds")
continue
else:
break
# A deduction from players total chips of the total bet
total_chips = (starting_chips - placed_bet)
losing_total = (starting_chips - placed_bet)
print('You now have: {}\n'.format(total_chips))
#If the player wins the hand
total_chips = ((placed_bet * 2) + starting_chips)
此处链接到整个代码-> https://github.com/Joeet33/CardGame
而不是拥有starting_chips
,为什么不只使用total_chips
并在while循环之前对其进行初始化?最终,您要修改的变量是“玩家拥有多少筹码”。 starting_chips
可以用作脚本STARTING_CHIPS = 1000
顶部提供的常量,然后将total_chips = STARTING_CHIPS
放在while循环的上方。
最终,每次while循环返回顶部时,它将所有值重置为原始值1000。