我正在写一个棒球比赛模拟.我希望能够运行多个游戏,看看不同的击球平均值如何影响结果.每个游戏都由"蝙蝠"组成,其结果来自随机数.
问题在于,当我去运行多个游戏时,每个游戏都会得到相同的结果.
我想Python正在记住函数的结果,只是使用它.我是Python/CS的新手,所以一直试图查找内存等问题,但我找不到我需要的答案.我感谢任何帮助或对资源的指导我会很感激.谢谢
以下是简化版本,以帮助我解释问题.它只使用了点击率,结束了27场比赛.最后它循环了五场比赛.
import random
hits = 0
outs = 0
# determine whether player (with .300 batting average) gets a hit or an out
def at_bat():
global hits
global outs
number = random.randint(0,1000)
if number < 300:
hits +=1
else:
outs += 1
# run at_bat until there are 27 outs
def game():
global hits
global outs
while outs < 27:
at_bat()
else:
print "game over!"
print hits
# run 5 games
for i in range(0,5):
game()
Run Code Online (Sandbox Code Playgroud) 基本上我想要做的是在我的程序中,我希望能够在Visual Express IDE中启用调试时启用详细调试.我将使用Define语句,但如何检查IDE中是否启用了调试
我已经花了一些时间试图找出这个网站上的问题,我最终发现了一个正如我所要求的那样有效的正则表达式
练习是:
Enter a regexp that matches all the items in the first column
(positive examples) but none of those in the second (negative examples).
When you press "submit", you will see what matched.
Positive Negative
pit pt
spot Pot
spate peat
slap two part
respite
Run Code Online (Sandbox Code Playgroud)
我找到的答案是
^\w?.*p[a-z ?]t\w?.*$
Run Code Online (Sandbox Code Playgroud)
我发现的是所有积极的话语都有某种形式p_t.
我匹配,p[a-z ?]t然后^\w?.*匹配任何前面的字母,p并\w?.*$匹配任何字母数字字符后t
我想知道的是有更好的方法来回答这个问题吗?