<p>当变量等于或小于0时,我的程序应该停止,但当程序运行时,如果变量大于0,代码将重置。你知道吗</p>
<p>这是我的密码:
主.py你知道吗</p>
<pre><code>import random
import os
import sys
global foodamount
foodamount = random.randint(1,10)
answer = str(input(("Right or Left")))
if answer == "Right" or answer == "right":
#Check if foodamount is greater than 1, then if it is run cave.py
foodamount = foodamount -1
if foodamount < 1:
print("You ran out of food. You lose")
sys.exit()
if foodamount > 0:
os.system('python cave.py')
</code></pre>
<p>这是洞穴.py你知道吗</p>
<p/><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div^{cl2}$
<pre class="snippet-code-js lang-js prettyprint-override"><code>import random
import sys
import os
import main
print("Do you want to attack?")
attak = str(input(("Yes or No")))
if attak == "Yes" or attak == "yes":
x = random.randint(1,2)
if x == 1:
os.system('python attack')
if x == 2:
print("You lose")
sys.exit()
if attak == "no" or attak == "No":
print("Do you leave the cave or go around the spider?")
y = str(input("Leave or Around"))
if y == "Leave" or y == "leave":
main.foodamount = main.foodamount -1
if main.foodamount < 1:
print("You ran out of food. You lose")
sys.exit()
else:
os.system('python test')</code></pre>
</div>
</div>
<p>当我用python运行这个程序时,程序从头开始,程序从头重新启动。你知道吗</p>
<p>如果你能帮上忙,我们将不胜感激。你知道吗</p>
<p>似乎您已经编写了一个脚本,如果满足某些条件,它将在最后自动运行。别这样。相反,编写一个实现游戏逻辑的函数,并在“while”循环中运行该函数,如下所示:</p>
<pre><code>def play_game():
if the player dies:
return False
return True
while play_game():
pass
</code></pre>