import sys import random import getopt def reward(red, blue): if blue == 1: if red <= 2: return 5 elif red == 3 : return 10 elif red == 4 : return 200 elif red == 5 : return 3000 elif red == 6 : return 10000000 else: if red == 4: return 10 elif red == 5: return 200 elif red == 6: return 5000000 def main(): get = False count = 0 award = [2, 5, 11, 17, 23, 31, 10] total = 0 while not get and count < int(sys.argv[1]): r=random.sample(range(1,34),6) r.append(random.choice(range(16))+1) red=0 for choice in r[0:6]: if choice in award: red+=1 blue=0 if r[-1] == award[-1]: blue+=1 if blue == 0 and red >= 4 or blue == 1: print("{}+{}".format(red,blue)) print(award, r) total += reward(red, blue) if (blue == 0 and red >= 5) or (blue == 1 and red >= 4): get = True count += 1 if not get: print("nope! cost", int(sys.argv[1])*2) else: print("count =", count, "reward =", total - count*2) if __name__ == "__main__": sys.exit(main())
使用方法,python buy.py 10000
赚到200元大奖为止
最欧的一次:count = 95 reward = 45, 买了95注,总回报45元。
这辈子都不想再买福彩了……