私がやろうとしているのは、変数 "FGlasgow" から食べ物を取り、それを変数 "食べ物" に追加することです. 素晴らしくシンプルです. しかし、FGlasgow が負になったときでも、スクリプトはさらに多くの時間がかかることに気付きました. Glasgow < 0 で食べ物を追加して乱数を取ります。問題は、これを短縮できるかどうか、そして私の方法が正しいかどうかです。
import random
def RandomNo():
Random = random.randint(0,50)
return Random
Food = 1
FGlasgow = 100
while True:
Random = RandomNo()
Food += Random
FGlasgow -= Random
while FGlasgow < 0:
Food -= Random
FGlasgow += Random
Random = RandomNo()
Food += Random
FGlasgow -= Random
print "You have found" , Random , "units of food"
助けてくれてありがとう:)どんな提案も素晴らしいでしょう:)