#对gameover函数判断测试 def gameOver(a,b): if (a>=25 and abs(a-b)>=2 )or(b>=25 and abs(a-b)>=2): return True else: return False ai=[] bi=[] try: for a,b in ((25,25),(26,25),(27,26),(29,25)): if gameOver(a,b): ai.append(a) bi.append(b) except: print(‘Error‘) print(ai) print(bi) #对simOneGame(proA,proB)函数进行测试 try: probA,probB=0.5,0.5 scoreA,scoreB=0,0 serving = "A" if serving == "A": if random() < probA: scoreA += 1 else: serving="B" else: if random() < probB: scoreB += 1 else: serving="A" print(scoreA) print(scoreB) except: print(‘Error‘) #对simNGames(n, probA, probB)进行测试 try: n,scoreA,scoreB=1,24,26 winsA, winsB = 0, 0 scoreA_ls=[] scoreB_ls=[] for i in range(n): scoreA_ls.append(scoreA) scoreB_ls.append(scoreB) if scoreA > scoreB: winsA += 1 else: winsB += 1 print(winsA, winsB,scoreA_ls,scoreB_ls) except: print(‘Error‘)
import requests from bs4 import BeautifulSoup def getHTMLText(url): try: r=requests.get(url,timeout=30) soup=BeautifulSoup(r.text) r.raise_for_status() r.encoding=‘utf-8‘ return r.text,r.status_code,len(r.text),r.encoding,len(soup.text) except: return "" url="http://www.google.cn/" for i in range(20): print(i) print(getHTMLText(url))
结果如下:
原文:https://www.cnblogs.com/hayhong/p/12881267.html