擅长:python、mysql、java
<p>让我向您介绍<code>while</code>循环。当您希望在指定的条件为true或false时发生某些事情时,可以使用此选项。在</p>
<p>我简短地编辑了你的代码。在</p>
<p>随机导入</p>
<pre><code>def main():
player1=20
player2=12
strength=(20-10)/5
strength_mod=int(strength)
while player1>0 and player2>0:
dice1=random.randint(1,6)
dice2=random.randint(1,6)
if dice1>dice2:
player1+=strength_mod
player2-=strength_mod
print("Player 1 strength is: ", player1)
print("Player 2 strength is: ", player2)
elif dice1<dice2:
player2+=strength_mod
player1-=strength_mod
print("Player 1 strength is: ", player1)
print("Player 2 strength is: ", player2)
main()
</code></pre>
<p>我给了玩家1和2的初始值打赌这些可以根据你的喜好改变。为了四舍五入,我创建了另一个变量,并将强度改为整数。在</p>